对JavaScript Max Blob大小有任何限制 [英] Is there any limitation on JavaScript Max Blob size

查看:1663
本文介绍了对JavaScript Max Blob大小有任何限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AJAX调用下载文件。我需要使用AJAX调用,因为我必须发出一个发布请求,我需要从客户端发送一些标题。由于Server API不受我们控制,除了使用AJAX之外,我们没有太多选择。为了显示文件保存对话框,我将字节数组转换为对象URL,如下所示

  var oReq = new的XMLHttpRequest(); 
oReq.open(POST,api / operations / zip,true);
oReq.responseType =arraybuffer;
oReq.onload = function(oEvent){
var blob = new Blob([oReq.response],{type:'application / octet-binary'});
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download =myFileName.zip; link.click();
}
oReq.send(filePaths);

现在我想知道有没有限制 Blob大小我们可以在JavaScript以外的浏览器内存约束。喜欢可以下载4 GB的文件,如果我有大约8 GB的内存。

解决方案

虽然重新设计正在进行中,Blob似乎限制在Chrome中的500MiB,并且目前存储在内存中: p>

https://code.google.com / p / chromium / issues / detail?id = 375297



其他浏览器实现的限制略有不同:



https://github.com/eligrey/FileSaver.js/#supported-browsers


I am trying to download a file using AJAX call. I need to use AJAX call because I have to make a post request along with that I need to send some headers from the client. As Server API is not under our control, we don't have much choice other than using AJAX. In order to show file save dialog, I am converting the byte array to blob to Object URL like shown below

var oReq = new XMLHttpRequest();
oReq.open("POST","api/operations/zip", true);
oReq.responseType = "arraybuffer";
oReq.onload = function(oEvent) { 
   var blob=new Blob([oReq.response], {type: 'application/octet-binary'}); 
   var link=document.createElement('a'); 
   link.href=window.URL.createObjectURL(blob); 
   link.download="myFileName.zip"; link.click();  
}
oReq.send(filePaths);

Now I would like to know is there any limit on Blob size we can have in JavaScript other than browser memory constraint. like is it possible to download 4 GB file if I have around 8 GB RAM.

解决方案

Blobs appear to be limited to 500MiB in Chrome and are currently stored in memory, though a redesign is in progress:

https://code.google.com/p/chromium/issues/detail?id=375297

Other browser implementations have slightly different limits:

https://github.com/eligrey/FileSaver.js/#supported-browsers

这篇关于对JavaScript Max Blob大小有任何限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆