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

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

问题描述

我正在尝试使用 AJAX 调用下载文件.我需要使用 AJAX 调用,因为我必须发出一个 post 请求,同时我需要从客户端发送一些标头.由于服务器 API 不在我们的控制之下,我们除了使用 AJAX 之外别无选择.为了显示文件保存对话框,我将字节数组转换为 blob 到对象 URL,如下所示

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);

现在我想知道除了浏览器内存限制之外,我们在 JavaScript 中对 Blob 大小 是否有任何限制.如果我有大约 8 GB 的 RAM,是否可以下载 4 GB 的文件.

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.

推荐答案

现有答案似乎已经过时.

The existing answer appears largely out of date.

根据 Chrome 的 Blob 存储系统设计/a>:

According to Chrome's Blob Storage System Design:

我们计算存储限制 此处.

  • 如果架构是 x64 而不是 ChromeOS 或 Android:2GB
  • 否则:total_physical_memory/5
  • 如果 Chrome 操作系统:disk_size/2
  • 如果安卓:disk_size/20
  • 否则:disk_size/10

注意:ChromeOS的磁盘是用户分区的一部分,与系统分区是分开的.

Note: ChromeOS's disk is part of the user partition, which is separate from the system partition.

我们限制我们的磁盘限制以适应最低磁盘可用性.我们使用的等式是:

We limit our disk limit to accomidate a minimum disk availability. The equation we use is:

min_disk_availability = in_memory_limit * 2

(所有大小以 GB 为单位)

(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

澄清一下,disk_size 显然是总磁盘大小,而不是可用磁盘空间(可能是出于隐私原因,但似乎可能会导致问题).

To clarify, disk_size is apparently the total disk size, not the available disk space (probably for privacy reasons, but seems like that could cause problems).

Chrome 使用 Chrome 配置文件目录中名为 blob_storage 的目录将 blob 部分存储到磁盘.

Chrome uses a directory called blob_storage in the Chrome profile directory to store blob parts to disk.

如果可用磁盘空间或可用 RAM 小于软件限制,我不确定是否或如何施加其他限制.当我知道更多时,我会更新这个答案.

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.

与 Chrome 相同,因为它基于 Chromium.

Same as Chrome, as it is based on Chromium.

没有明显的硬限制.我能够创建比800 MiB"FileSaver.js 声明大得多的 Blob.它不使用磁盘空间来支持更大的 blob,所以它都在内存中,可能与操作系统将内存分页到磁盘.这意味着可能会出现大于内存的 blob,但性能可能会很差.

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.

没有明显的硬限制.它不使用磁盘空间来支持更大的 blob,所以它都在内存中,可能与操作系统将内存分页到磁盘.这意味着可能会出现大于内存的 blob,但性能可能会很差.

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.

其他浏览器限制将随着我的学习而添加.

Other browser limits will be added as I learn them.

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

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