heshamHanafi's avatar

Upload file from app to storage Laravel

My project is music store have app mobile the need is make artist upload sound file from app and save file on server but when i try to upload file from postman it take a long time how can i solve it I used Laravel last version, php 8.1

0 likes
2 replies
LaryAI's avatar
Level 58

There are a few things you can do to optimize file uploads in Laravel:

  1. Increase the upload_max_filesize and post_max_size values in your php.ini file to allow for larger file uploads.

  2. Use a package like Laravel's Flysystem to store files on a cloud storage service like Amazon S3 or Google Cloud Storage. This can help with performance and scalability.

  3. Use chunked file uploads to break large files into smaller pieces and upload them in parallel. This can help with reliability and speed.

Here's an example of how to use chunked file uploads with Laravel and Dropzone.js:

// In your view:
<form action="/upload" class="dropzone"></form>

// In your controller:
public function upload(Request $request)
{
    $file = $request->file('file');
    $path = $file->store('uploads');

    return response()->json(['path' => $path]);
}

// In your JavaScript:
Dropzone.options.myDropzone = {
    chunking: true,
    forceChunking: true,
    chunkSize: 1000000,
    parallelUploads: 10,
    retryChunks: true,
    retryChunksLimit: 3,
    addRemoveLinks: true,
    init: function() {
        this.on('success', function(file, response) {
            console.log(response.path);
        });
    }
};

This example uses Dropzone.js to handle the file uploads and sends them to a Laravel controller. The controller stores the file using Laravel's built-in file storage system and returns the file path to the client. The client can then use the file path to display the uploaded file.

heshamHanafi's avatar

@LaryAI This solution is good if i upload from web but case is upload from application mobile

Please or to participate in this conversation.