dropzone icon indicating copy to clipboard operation
dropzone copied to clipboard

Upload Files directly to Amazon S3 bucket the progress bar is not working correctly using Laravel 5

Open usamamashkoor opened this issue 9 years ago • 11 comments

Hi i am exploring the Github but i am seeing that people are facing some issues while uploading files to Amazon S3 Bucket. So can some one please let me know if dropzone js supports the Amazon S3 file upload yet...? If it supports the S3 then kindly please take a look at my code see why the progress bar of Dropzone js is not working correctly.

Here is the Case when ever i upload file directly to the Amazon S3 Bucket using dropzone then the progress bar quickly reaches 100% mean while the file is still uploading on the Amazon S3 bucket. Here is my code

   ```
   Dropzone.autoDiscover = false;

          myDropzone = new Dropzone("div#dropzoneFileUpload", {
              url: baseUrl + "/challenge/store",
              success : function(file, response){
                alert('success')
              },

              error : function(file, response){
                this.removeAllFiles()
              
          
              },
              uploadProgress: function(progress) {
                // The event does not work when ever file is select it say 100 in alert 
                  alert(progress);
                  document.querySelector("#total-progress .progress-bar").style.width = progress + "%";
              },
             
              autoProcessQueue: false,
              maxFiles: 1,
              maxFilesize: 20480, // MB
              addRemoveLinks: true,
              acceptedFiles: "video/*,mp4,.mkv,.avi,.flv,.3gp,.mov,.wmv,.webm",
              params: {
                  _token: token,
              }
          });

I am using Php Laravel on server side i am not putting file on my server i am directly uploading the file to Amazon S3 Bucket Here is my Laravel Code



$file = $request->file( 'file' );
$s3 = \Storage::disk('s3');
$filePath = '/buckVideo/' . $name;
$isS3VideoUpload = $s3->put($filePath, file_get_contents($file), 'public');

the file is successfully uploaded to Amazon S3 bucket but progress bar is not working correctly.It goes to 100% directly in an instant.While the server takes time give the response..

usamamashkoor avatar Dec 29 '16 06:12 usamamashkoor

@usamamashkoor . Did you find a solution to that problem ? I have the same one

ghost avatar Feb 25 '17 01:02 ghost

@quaidesbalises i am not using it now i have developed my own script for this purpose... using jquery ajax native functions...

usamamashkoor avatar Feb 25 '17 11:02 usamamashkoor

Same problem...

AmityTek avatar Sep 07 '17 22:09 AmityTek

same here!

philippkuehn avatar Nov 06 '17 19:11 philippkuehn

anyone got solution for this?

shanka12 avatar Dec 06 '17 04:12 shanka12

Same problem here ? Any news ?

benjbdev avatar May 21 '18 14:05 benjbdev

I have used the amazon s3 Javascript Browser SDK for the progress bar upload. You can check the more details about it here. https://aws.amazon.com/sdk-for-browser/

usamamashkoor avatar May 23 '18 07:05 usamamashkoor

I have error- Access to XMLHttpRequest at 'https://4kd2hi3ere.execute-api.us-east-1.amazonaws.com/default/myfirstvuecode' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

how to solve this error

ShrJoshi28 avatar Jan 30 '19 10:01 ShrJoshi28

In amazon S3, you need to setup a CORS configuration to allow for all hosts whilst you are testing on localhost. I usually open up everything in development mode when i hit an issue. That way i can tell if its a client issue or an S3 access issue. e.g.

<?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>HEAD</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>PUT</AllowedMethod> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <AllowedHeader>*</AllowedHeader> <ExposeHeader>ETag</ExposeHeader> </CORSRule> </CORSConfiguration>

Once in production, this should be restricted to only the the origin(s) and method(s) required.

ghost avatar Jan 30 '19 21:01 ghost

@rhnetig its not working still getting error please suggest.

ShrJoshi28 avatar Jan 31 '19 08:01 ShrJoshi28

@rhnetig as you suggested above configuration i changes CORSConfiguration having following errors At front end- Access to XMLHttpRequest at 'https://4kd2hi3ere.execute-api.us-east-1.amazonaws.com/default/myfirstvuecode' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. lambda.js?ba28:16 Error: Network Error at createError (eval at (app.js:798), :15:15) at XMLHttpRequest.handleError (eval at (app.js:780), :87:14)

And in CloudWatch - 05:21:52 START RequestId: 26c51933-b1e7-43a9-be6d-5b34e70989ad Version: $LATEST START RequestId: 26c51933-b1e7-43a9-be6d-5b34e70989ad Version: $LATEST  05:21:52 END RequestId: 26c51933-b1e7-43a9-be6d-5b34e70989ad END RequestId: 26c51933-b1e7-43a9-be6d-5b34e70989ad  05:21:52 REPORT RequestId: 26c51933-b1e7-43a9-be6d-5b34e70989ad Duration: 225.02 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 33 MB REPORT RequestId: 26c51933-b1e7-43a9-be6d-5b34e70989ad Duration: 225.02 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 33 MB

Please help.

ShrJoshi28 avatar Feb 04 '19 05:02 ShrJoshi28