简体   繁体   中英

How to upload large files to Amazon S3 from Laravel?

I want users to upload large files (like HD videos and big PDFs) and am using this line of code to upload the files. Storage::disk('s3')->putFile('uploads', new File($request->file('file_upload')));

the problem is even though I have a good internet speed it takes a very long time to upload the file. what can I do to get a faster file upload?

There are actually two network calls involved in the process.

  1. From client-side the file gets uploaded to your server.
  2. Via server-to-server call the file gets uploaded from your server to s3.

The only way to reduce the delay is to directly upload the files from client to s3 using client-side SDKs securely. With this the files will be directly stored in the S3 bucket.

Once the files are uploaded to s3 via AWS S3 client-side SDKs, you can post the attributes of the file along with the download URL to Laravel and update it to DB.

The plus point of this approach is it allows you to show actual file upload progress at the client-side.

This can be done via the AWS amplify library which provides great integration with S3: https://docs.amplify.aws/start

The other options:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM