简体   繁体   English

使用PHP的带有进度栏的Amazon S3分段上传

[英]Amazon S3 multipart uploads with progress bar using PHP

How do I get the progress of a multipart uploader? 如何获得分段上传器的进度?

This is what I have and the progress callback is never called. 这就是我所拥有的,并且永远不会调用进度回调。 Is it possible to get progress through the PHP SDK? 通过PHP SDK是否可以取得进展?

$uploader = new MultipartUploader($s3Client, $uploadedFile->getRealPath(), [
    'bucket' => env('AWS_BUCKET'),
    'key' => $filename,
    '@http' => [
        'progress' => function ($expectedDl, $dl, $expectedUl, $ul) {
            // This never gets called
        }
    ]
]);

I ended up finding a solution on my own. 我最终自己找到了解决方案。 You pass a "params" key in the configuration array parameter containing the @http progress event callback. 您在包含@http progress事件回调的配置数组参数中传递“ params”键。

params: (array) An array of key/value parameters that will be applied to each of the sub-commands run by the uploader as a base. params :(数组)键/值参数的数组,这些数组将应用于上载程序作为基础运行的每个子命令。

$uploader = new MultipartUploader($s3Client, $uploadedFile->getRealPath(), [
    'bucket' => env('AWS_BUCKET'),
    'key' => $filename,
    'params' => [
        '@http' => [
            'progress' => function ($expectedDl, $dl, $expectedUl, $ul) {
                // This gets called
            }
        ]
    ]
]);

First try was close, but I wish this feature was more visible in guides as progress bars are a common UI element. 第一次尝试已经结束,但是我希望此功能在指南中更加明显,因为进度条是常见的UI元素。

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

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