3

I'm using XMLHttpRequest to upload images to my server in a post request and the images are in base64 format. I looked all over the web and found that i can add a "progress" event to the upload. but it only fires when upload is complete... how can I get upload progress for such request in react-native?

const http = new XMLHttpRequest();

http.upload.addEventListener("progress", function(e){}); // first attempt, not working...
http.addEventListener("progress", function(e){}); //second attempt, not working...


http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Accept", "application/json, application/xml, text/plain, text/html, *.*");
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");

http.send(params);

The answers mentioned in How to get progress from XMLHttpRequest don't work. My guess is that react-native requires a different solution.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Scianid
  • 143
  • 9
  • 1
    Possible duplicate of [How to get progress from XMLHttpRequest](https://stackoverflow.com/questions/76976/how-to-get-progress-from-xmlhttprequest) – Val Dec 04 '17 at 02:31
  • tried everything that's mentioned there but its not working. seems to me to be related to react native but i don't really know. – Scianid Dec 04 '17 at 10:29
  • Did you find a solution? – Marklar Mar 07 '18 at 02:10
  • not yet. The only progress i got was that it does work on iOS. but doesnt fire on android. – Scianid Mar 13 '18 at 10:27
  • Try this: https://stackoverflow.com/questions/15965651/progress-bar-while-uploading-large-files-with-xmlhttprequest – Vladimír May 07 '19 at 07:18

0 Answers0