简体   繁体   English

使用php直接上传到带有进度条的s3

[英]Direct upload to s3 with progress bar using php

In regards to this question Upload File Directly to S3 with Progress Bar , i would like to know if there is an update or another way to do this without using a flash or java applet? 关于这个问题使用进度条直接上传文件到S3 ,我想知道是否有更新或其他方式来执行此操作而不使用Flash或Java小程序?

I have tried using this swfupload_s3 http://swfupload.org/forum/generaldiscussion/2185 , it works but unfortunately the progress bar shoots to 100% and found this, 我已经尝试过使用这个swfupload_s3 http://swfupload.org/forum/generaldiscussion/2185 ,它有效,但不幸的是进度条射到100%并发现了这一点,

(1) Local Proxy Servers and some Anti-Virus software will cause this behavior. (1)本地代理服务器和某些防病毒软件会导致此行为。 Instead of sending the upload to the server the anti-virus software intercepts the upload and accepts the entire file. 防病毒软件不会将上传内容发送到服务器,而是拦截上传并接受整个文件。 SWFUpload has sent the entire file and displays 100%. SWFUpload已发送整个文件并显示100%。 This happens quickly because nothing has been sent out yet, it's all happened local. 这种情况很快发生,因为还没有发出任何东西,这一切都发生在当地。 The anti-virus then scans the intercepted file and sends it on to the server. 然后,防病毒软件扫描截获的文件并将其发送到服务器。 Meanwhile SWFupload is sitting tight at 100%. 与此同时,SWFupload紧随其后。 Once the anti-virus has sent the file the server responds and SWFUpload "completes" 一旦反病毒发送文件,服务器响应并且SWFUpload“完成”

(2) Known issue. (2)已知问题。 We have already documented this. 我们已经记录了这一点。 There is no work around. 没有工作。 This is how it will work for any client side only uploading tool when anti-virus interferes with the upload 当反病毒干扰上传时,这就是任何客户端只能上传工具的方式

http://swfupload.org/forum/generaldiscussion/642 (1) http://swfupload.org/forum/generaldiscussion/642(1
http://code.google.com/p/swfupload/issues/detail?id=213 (2) http://code.google.com/p/swfupload/issues/detail?id=213(2

I have been on this for 2 days but I can't seem to find another way. 我已经在这2天了,但我似乎找不到另一种方式。 Or there isn't at all? 或者根本没有?

I managed to get this working on AWS' PHP SDK v3. 我设法让这个工作在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 . AWS文档 - S3 Config部分对此进行了解释。 It works by exposing GuzzleHttp's progress property-callable, as explained in this SO answer . 它的工作原理是暴露GuzzleHttp的progress属性 - 可调用,如本SO答案所述

There's an open source php script with an S3 API for file uploads, it does return the progress of the upload in realtime and you can customize the Uploader UI as well if you so desire: 有一个带有用于文件上传的S3 API的开源PHP脚本,它确实实时返回上传的进度,如果您愿意,还可以自定义上传器UI:

http://www.plupload.com/ http://www.plupload.com/

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

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