Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Firefox中使用xmlhttprequest和二进制数据,即图像?_Javascript_Firefox_Binary_Xmlhttprequest - Fatal编程技术网

Javascript 如何在Firefox中使用xmlhttprequest和二进制数据,即图像?

Javascript 如何在Firefox中使用xmlhttprequest和二进制数据,即图像?,javascript,firefox,binary,xmlhttprequest,Javascript,Firefox,Binary,Xmlhttprequest,我现在正在看 function readDataFromURL(fuFullHttpURL, fuCallMeOnLoad) { var MyThis = this; this.fullHttpURL = fuFullHttpURL; this.callMeOnLoad = fuCallMeOnLoad; var oReq = new XMLHttpRequest(); oReq.open("GET", MyThis.fullHttpURL, true);

我现在正在看

function readDataFromURL(fuFullHttpURL, fuCallMeOnLoad) {
    var MyThis = this;
    this.fullHttpURL = fuFullHttpURL;
    this.callMeOnLoad = fuCallMeOnLoad;
    var oReq = new XMLHttpRequest();
    oReq.open("GET", MyThis.fullHttpURL, true);
    oReq.responseType = "arraybuffer";
    oReq.onload = function(oEvent) {
        var blob = new Blob([oReq.response], {type: "image/jpg"});
        MyThis.callMeOnLoad(blob);
    };
    oReq.send();
}
但这只是为了下载。如何使用此代码上载? 前几年,当我尝试使用xmlhttprequest下载图像时,下载的大小受到限制。还有尺码限制吗? 以前,每个浏览器对这个尺寸限制的处理方式都不同,所以我自己无法测试


编辑:似乎解释了上传。

您可以使用
FormData
在XMLHttpRequest中发送文件,如下所示。尽管Chrome&FF支持它,但它只在IE10或更高版本中工作

  var xhr = new XMLHttpRequest();
  var file = document.getElementById("fileUpload");
  var formData = new FormData();
  formData.append("upload", file.files[0]);
  xhr.open("post", "your-url", true);
  xhr.setRequestHeader("Content-Type", "multipart/form-data");
  xhr.upload.onload = function(event){
    // handle successful upload
  };
  xhr.send(formData);  

泰!所以原则上我现在可以处理上传和下载了。(我也发现了)-因此,我读到的只是关于下载的大小限制的问题。(我只能在Firefox中测试,我不确定我的测试是否可靠,因为这里有一些当前的特定设置。)我在网页中有一些动态创建的图像标签。如何访问图像数据并上传?有关下载限制的更多信息,请参阅您使用的是
canvas
,还是仅使用
img
?我实际上有一个canvas。