JavaScript Max Blob 大小是否有任何限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28307789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any limitation on JavaScript Max Blob size
提问by Vikash
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
我正在尝试使用 AJAX 调用下载文件。我需要使用 AJAX 调用,因为我必须发出一个 post 请求,同时我需要从客户端发送一些标头。由于服务器 API 不在我们的控制之下,我们除了使用 AJAX 之外别无选择。为了显示文件保存对话框,我将字节数组转换为 blob 到对象 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);
Now I would like to know is there any limit on Blob sizewe 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.
现在我想知道除了浏览器内存限制之外,我们在 JavaScript 中对Blob 大小是否有任何限制。如果我有大约 8 GB 的 RAM,是否可以下载 4 GB 的文件。
回答by Alexander O'Mara
The existing answer appears largely out of date.
现有的答案似乎已经过时了。
Chrome (57+ it appears):
Chrome(出现 57+):
According to Chrome's Blob Storage System Design:
Blob Storage Limits
We calculate the storage limits here.
In-Memory Storage Limit
- If the architecture is x64 and NOT ChromeOS or Android:
2GB- Otherwise:
total_physical_memory / 5Disk Storage Limit
- If ChromeOS:
disk_size / 2- If Android:
disk_size / 20- Else:
disk_size / 10Note: ChromeOS's disk is part of the user partition, which is separate from the system partition.
Minimum Disk Availability
We limit our disk limit to accomidate a minimum disk availability. The equation we use is:
min_disk_availability = in_memory_limit * 2Example Limits
(All sizes in GB)
Device | Ram | In-Memory Limit | Disk | Disk Limit | Min Disk Availability ----------------+-----+-----------------+------+------------+---------------------- Cast | 0.5 | 0.1 | 0 | 0 | 0 Android Minimal | 0.5 | 0.1 | 8 | 0.4 | 0.2 Android Fat | 2 | 0.4 | 32 | 1.5 | 0.8 CrOS | 2 | 0.4 | 8 | 4 | 0.8 Desktop 32 | 3 | 0.6 | 500 | 50 | 1.2 Desktop 64 | 4 | 2 | 500 | 50 | 4
Blob 存储限制
我们在这里计算存储限制。
内存存储限制
- 如果架构是 x64 而不是 ChromeOS 或 Android:
2GB- 除此以外:
total_physical_memory / 5磁盘存储限制
- 如果 Chrome 操作系统:
disk_size / 2- 如果安卓:
disk_size / 20- 别的:
disk_size / 10注意:ChromeOS 的磁盘是用户分区的一部分,与系统分区是分开的。
最低磁盘可用性
我们限制我们的磁盘限制以适应最低磁盘可用性。我们使用的等式是:
min_disk_availability = in_memory_limit * 2示例限制
(所有大小以 GB 为单位)
Device | Ram | In-Memory Limit | Disk | Disk Limit | Min Disk Availability ----------------+-----+-----------------+------+------------+---------------------- Cast | 0.5 | 0.1 | 0 | 0 | 0 Android Minimal | 0.5 | 0.1 | 8 | 0.4 | 0.2 Android Fat | 2 | 0.4 | 32 | 1.5 | 0.8 CrOS | 2 | 0.4 | 8 | 4 | 0.8 Desktop 32 | 3 | 0.6 | 500 | 50 | 1.2 Desktop 64 | 4 | 2 | 500 | 50 | 4
To clarify, disk_sizeis apparently the total disk size, not the available disk space (probably for privacy reasons, but seems like that could cause problems).
澄清disk_size一下,显然是总磁盘大小,而不是可用磁盘空间(可能是出于隐私原因,但似乎可能会导致问题)。
Chrome uses a directory called blob_storagein the Chrome profile directory to store blob parts to disk.
Chrome 使用blob_storage在 Chrome 配置文件目录中调用的目录将 blob 部分存储到磁盘。
I'm not sure if or how some other limits are imposed if available disk space or available RAM are less than the software limits. I'll update this answer when I know more.
如果可用磁盘空间或可用 RAM 小于软件限制,我不确定是否或如何施加其他一些限制。当我知道更多时,我会更新这个答案。
Opera (44+ or perhaps earlier):
Opera(44+ 或更早):
Same as Chrome, as it is based on Chromium.
与 Chrome 相同,因为它基于 Chromium。
Firefox (53+ or perhaps earlier):
Firefox(53+ 或更早):
No apparent hard limit. I am able to create Blob's significantly larger than the "800 MiB" FileSaver.js claims. It does not use disk space to back larger blobs, so it all goes in memory, potentially with the operating system paging memory to disk. This means that blobs larger than memory may be possible, though likely with bad performance.
没有明显的硬限制。我能够创建比“800 MiB”FileSaver.js 声明大得多的 Blob。它不使用磁盘空间来支持更大的 blob,所以它都在内存中,可能与操作系统将内存分页到磁盘。这意味着比内存大的 blob 是可能的,尽管性能可能很差。
Safari (10.1+ or perhaps earlier):
Safari(10.1+ 或更早版本):
No apparent hard limit. It does not use disk space to back larger blobs, so it all goes in memory, potentially with the operating system paging memory to disk. This means that blobs larger than memory may be possible, though likely with bad performance.
没有明显的硬限制。它不使用磁盘空间来支持更大的 blob,所以它都在内存中,可能与操作系统将内存分页到磁盘。这意味着比内存大的 blob 是可能的,尽管性能可能很差。
Other browser limits will be added as I learn them.
当我学习它们时,将添加其他浏览器限制。
回答by Klaus
Blobs appear to be limited to 500MiB in Chrome and are currently stored in memory, though a redesign is in progress:
Blob 在 Chrome 中似乎被限制为 500MiB,并且当前存储在内存中,但正在进行重新设计:
https://code.google.com/p/chromium/issues/detail?id=375297
https://code.google.com/p/chromium/issues/detail?id=375297
Other browser implementations have slightly different limits:
其他浏览器实现的限制略有不同:

