1

Trying to upload a file to a servlet using following code:

    var fd = new FormData();
    fd.append("file", document.getElementById('fileToUpload').files[0]);
    var xhr = new XMLHttpRequest();
    xhr.upload.addEventListener("progress", uploadProgress, false);
    xhr.upload.addEventListener("load", transferComplete, false);
    xhr.addEventListener("error", onError, false);
    xhr.addEventListener("abort", onUploadCanceled, false);

    xhr.open("POST", urlManager.getUploadHandlerUrl());
    xhr.send(fd);

The problem is only in chrome(works in Firefox perfectly), saying that Failed to load the resource and the problem is not consistent. It uploads once or twice at times starts shouting. When this is the error it doesnot even make call to the server.

Tried using jquery from the sample in this quesion. But no benefit.

I could not figure how something like this can happen. I appreciate any leads, thanks.

enter image description here

EDIT: When I wrapped my XHR and explicitly set asynchronous as told in another SO answer, it is working for atleast 3-4 uploads and starting to shout.(a bit better than earlier). I am doubtful whether it had a effect for real.
When the state change is happened I am logging the ready state and status. The readyState just jumps from 1 to 4 and the status is left with 0.

Community
  • 1
  • 1
Prakash
  • 823
  • 12
  • 28

1 Answers1

1

I also had similar problem, my problem was solved by solving HTTP vs HTTPS conflict.

if the page that uploads the file is served from HTTP and post request that you are making is HTTPS then it may give "resource failed to load" error in chrome, thats what was happening in my case.

Page served and Post request both should be HTTP or both should be HTTPS , it can be combination of both.

I made both HTTP and my problem was solved. Let me know if that solved your problem as well .best luck.