简体   繁体   English

如何将大文件从 Laravel 上传到 Amazon S3?

[英]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.我希望用户上传大文件(如高清视频和大 PDF),并使用这行代码上传文件。 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.通过服务器到服务器调用,文件从您的服务器上传到 s3。

The only way to reduce the delay is to directly upload the files from client to s3 using client-side SDKs securely.减少延迟的唯一方法是使用客户端 SDK 安全地将文件从客户端直接上传到 s3。 With this the files will be directly stored in the S3 bucket.这样,文件将直接存储在 S3 存储桶中。

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.通过 AWS S3 客户端 SDK 将文件上传到 s3 后,您可以将文件的属性与下载的 URL 一起发布到 Laravel 并将其更新到 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这可以通过 AWS amplify 库完成,该库提供与 S3 的出色集成: https://docs.amplify.aws/start

The other options:其他选项:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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