无法加载资源帧加载中断的safari blob

时间:2016-05-24 08:25:38

标签: javascript safari blob

我进行ajax调用并将文件下载为基本64字符串并将其转换为blob然后下载它。它在除safari之外的所有浏览器中都能正常工作。我搜遍了所有的论坛,但没有运气。请帮我解决这个问题

错误:无法加载资源:帧加载中断

Safari版本:版本9.1

以下是我的代码:

            var blob = b64toBlob(fileContent, mimeType);
            var url = window.URL.createObjectURL(blob);
            anchor.setAttribute('href', url);
            anchor.setAttribute('download', fileName);
            console.log("downloading contents");
            // trigger click event
            var ev = document.createEvent("MouseEvents");
            ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            anchor.dispatchEvent(ev);


function b64toBlob(b64Data, contentType, sliceSize) {
          contentType = contentType || '';
          sliceSize = sliceSize || (512*1024);

          var byteCharacters = atob(b64Data);
          var byteArrays = [];
          for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {


            var slice = byteCharacters.slice(offset, offset + sliceSize);

            var byteNumbers = new Array(slice.length);
            for (var i = 0; i < slice.length; i++) {
              byteNumbers[i] = slice.charCodeAt(i);
            }

            var byteArray = new Uint8Array(byteNumbers);

            byteArrays.push(byteArray);

          }
          console.log("Read Completed:"
                    + (byteArrays.length));

          try{
               var blob = new Blob( byteArrays, {type : contentType});
               console.log("bLob Size:"
                        + (blob.size));
              return blob;
            }
            catch(e){
            }
}

0 个答案:

没有答案