danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 385 forks source link

Upload success not consistent #74

Open akosiraffy opened 6 years ago

akosiraffy commented 6 years ago

I'm using your plugin with Openload Api (https://openload.co/api#upload) but i'm having trouble figuring out what causing the problem. Sometime the upload get successful while sometimes, specially on big file (bigger than 1mb) the upload stuck on 100% progress and not reaching the .onUploadSuccess. I get the error by using .onUploadError and here's what I got:

xhr: {"readyState":0,"responseText":"","responseJSON":null,"status":0,"statusText":"error"} status: error errorThrown:

Here is my current code:

$("#home-drop-area").dmUploader({
    url : uploadurl,
    maxFileSize : 1073741824, // 1G max upload
    multiple : false,
    dataType : 'json',
    method : 'POST',
    onUploadProgress: function(id, percent){
    console.log(percent);
},
    onUploadComplete : function(){
        console.log('File Uploaded Successfully!');
    },
    onUploadError : function(id, xhr, status, errorThrown) {
        console.log('xhr: ' + JSON.stringify(xhr) + '\n status: ' + status + '\n errorThrown: ' + errorThrown);
}
});

Does the plugin transfer using with multipart/form-data encoded?

SapientHetero commented 5 years ago

I'm having a similar problem, mostly when uploading multiple very small files. I'll see several successful uploads, then one hangs and never completes.

When this occurs, the file being uploaded when the script hangs has been completely uploaded but the response is not detected. I can see the server sent the JSON response, but breakpoints set on the success and complete functions are not triggered when the upload "fails". I believe the progress update events are preventing the success and/or complete events from occurring.

I disabled the progress updates in jquery-dm-uploader.js (see code snippet below), after which uploads were MUCH more reliable but still not perfect. I'm going to test a "Promise"-based approach to progress reporting (https://github.com/likerRr/jq-ajax-progress) and see if that works better.

Incidentally, I'm not having problems with large files. I'm running a large-file upload test on my embedded server right now. The file is ~2GB long, and 864MB have uploaded so far without incident.


   file.jqXHR = $.ajax({
      url: file.widget.settings.url,
      type: file.widget.settings.method,
      dataType: file.widget.settings.dataType,
      data: fd,
      headers: file.widget.settings.headers,
      cache: false,
      contentType: false,
      processData: false,
      forceSync: false,
      //xhr: function() { return file.getXhr(); },```
SapientHetero commented 5 years ago

Update: My problem was due to a bug in my server code, not in this script. Once fixed, I re-enabled progress updates and am able to upload multiple files of any size. My largest upload to-date was a 1,085,177,688 byte whopper.