仅在Edge

时间:2019-07-19 10:13:31

标签: javascript html5-canvas microsoft-edge

我试图从其他域检索照片,然后将其添加到formdata中以将其发送到我的API。我正在用帆布做。它可以在Firefox,Chrome和IE中完美运行。但是在Edge中,控制台出现错误:SCRIPT5022:SecurityError及其指向context.drawImage()的错误。发布请求甚至不会触发。

我试图从crossOrigins匿名切换为Use-credentials,但这并没有改变。我已经在代码中加入了onload函数,但是发送到我的API的formdata却没有图片的痕迹。

var nbSelected = document.getElementsByClassName("selected").length;
for (i=0; i<nbSelected;i++){
var canvas = document.createElement("canvas");
      var image = document.getElementsByClassName("selected")[i];
      image.setAttribute("crossOrigin","anonymous");
      var context = canvas.getContext("2d");

      canvas.width = image.naturalWidth;
      canvas.height = image.naturalHeight;
      //in Edge the error points out to the following line
      context.drawImage(image, 0, 0,canvas.width,canvas.height);
      var dataUrlCanvas = canvas.toDataURL('image/png',1.0);
      var otherBlob = dataURLtoBlob(dataUrlCanvas);
      const filename = "file"+i+".png";
      const file = new Blob([otherBlob],{type:"image/png"});
      formData.append(filename, file, filename);
   }

0 个答案:

没有答案