简体   繁体   中英

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?

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,

(1) Local Proxy Servers and some Anti-Virus software will cause this behavior. 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%. 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%. Once the anti-virus has sent the file the server responds and SWFUpload "completes"

(2) Known issue. 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://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. Or there isn't at all?

I managed to get this working on 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 .

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:

http://www.plupload.com/

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