React Native和XMLHttpRequest - 上传进度条

时间:2017-12-03 21:12:02

标签: react-native upload xmlhttprequest base64

我正在使用XMLHttpRequest在发布请求中将图片上传到我的服务器,图片以base64格式。我查看了整个网络,发现我可以在上传中添加“进度”事件。但只有在上传完成后才会触发......如何在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);

修改

这里提到的答案:How to get progress from XMLHttpRequest 不工作我的猜测是本地反应需要不同的解决方案。

0 个答案:

没有答案