PHP S3上传进度 [英] PHP S3 upload progress

查看:85
本文介绍了PHP S3上传进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已经发生了很多次,但我仍然有些困惑.很多答案只能说自己在谈论上传进度栏,而没有从S3上传中获取实际的上传进度.

我已经阅读了许多问题并找到了许多软件,但是我仍然离理解S3上载的基本问题还很近.

是否有一种上传到S3的方式,同时了解该上传的进度,而不必先使用自己的应用服务器资源将文件存储在temp目录中?

我是否必须先将文件存储在我自己的服务器上,然后再推送到S3?我听说人们一次谈论到S3的流式传输(一次一个块),但是我不确定这涉及什么.想象一下,我是从客户端上传到HTML页面中的,如何将来自一个多部分的文件逐块地流化呢?(我看不到任何这样的例子,仅是文件在您的系统上的时间的例子,您知道这些块是有点无用的tbh).

API文档中当然有一个上传进度示例,但同样假设该文件首先位于您的服务器上,并且不是来自用户提供的另一台计算机.

我最初的想法是制作一个PHP脚本,该脚本可以每次上载一次即可对AWS进行一次ping操作.我正在查看API,以查看它们是否支持类似的功能,但运气不好.让我知道是否有东西...

进一步的这样做是Flash唯一的方法吗?

谢谢

解决方案

,可以在AWS PHP SDK v3中使用.

  $ client = new S3Client(/* config */);$ result = $ client-> putObject(['桶'=>存储桶名称",'密钥'=>'bucket-name/file.ext','SourceFile'=>'local-file.ext','ContentType'=>应用程序/pdf",'@http'=>['progress'=>函数($ downloadTotalSize,$ downloadSizeSoFar,$ uploadTotalSize,$ uploadSizeSoFar){printf(已下载%s的%s,已上传%s的%s.\ n",$ downloadSizeSoFar,$ downloadTotalSize,$ uploadSizeSoFar,$ uploadTotalSize);}]]); 

AWS文档中对此进行了解释-.如此SO答案所述,它通过公开GuzzleHttp的 progress 属性可调用而起作用..>

This has gone around a number of times but I'm still a bit bewildered. A lot of answers only copncern themselves with talking about upload progress bars and not getting the actual upload progress from an S3 upload.

I have read a number of questions and found a number of software pieces but I am still no closer to understanding the fundamental question of S3 uploads.

Is there a way of uploading to S3 while understanding the progress of that upload without having to use my own app servers resources to store the file in the temp directory first?

Do I have to store the file on my own server first and then push to S3? I have heard people talk about streaming bit at a time to S3 (one chunk at a time) but I am unsure what this involves. Imagine I was uploading from client side in a HTML page how would I stream the file chunk by chunk from a multi-part from as it comes in? (I don't see any example of that only an example of when the file is already on your system and you know the chunks which is kinda useless tbh).

There is of course an example of upload progress in the API docs but again that is assuming the file is on your server first and is not coming from another computer supplied by the user.

EDIT: My original thought was to make a PHP script that could ping AWS once every so oftern getting upload progress. I am looking through the API to see if they do support something like that but atm no luck. Let me know if there is something...

Further EDIT: Is flash the only way to go with this?

Thanks,

解决方案

YES, it is possible in AWS PHP SDK v3.

$client = new S3Client(/* config */);

$result = $client->putObject([
    'Bucket'     => 'bucket-name',
    'Key'        => 'bucket-name/file.ext',
    'SourceFile' => 'local-file.ext',
    'ContentType' => 'application/pdf',
    '@http' => [
        'progress' => function ($downloadTotalSize, $downloadSizeSoFar, $uploadTotalSize, $uploadSizeSoFar) {
            printf(
                "%s of %s downloaded, %s of %s uploaded.\n",
                $downloadSizeSoFar,
                $downloadTotalSize,
                $uploadSizeSoFar,
                $uploadTotalSize
            );
        }
    ]
]);

This is explained in the AWS docs - S3 Config section. It works by exposing GuzzleHttp's progress property-callable, as explained in this SO answer.

这篇关于PHP S3上传进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆