简体   繁体   English

为什么Javascript上传块大小会因浏览器而改变?

[英]Why Javascript upload chunk sizes change by browser?

I am uploading files by javascript code to server. 我正在通过javascript代码将文件上传到服务器。 I noticed that different browsers are sending bytes of different sizes. 我注意到不同的浏览器正在发送不同大小的字节。 As you can see in the following pictures, Internet Explorer is sending small bytes but Chrome and Firefox send bigger bytes. 正如您在下面的图片中看到的那样,Internet Explorer发送的是小字节,但Chrome和Firefox会发送更大的字节。

  1. I am uploading files with XMLHttpRequest. 我正在使用XMLHttpRequest上传文件。 Can I set standard upload bytes for all browsers? 我可以为所有浏览器设置标准上传字节吗? Because different size flow is giving errors on some browsers. 因为不同大小的流量在某些浏览器上出错。 Http error is 404.13. Http错误是404.13。
  2. I configured web.config file as <requestLimits maxAllowedContentLength="1073741824"> (1GB) but when I upload a big file(500 Mb) with Firefox and Chrome, the server is giving system.OutOfMemoryException. 我将web.config文件配置为<requestLimits maxAllowedContentLength="1073741824"> (1GB),但是当我使用Firefox和Chrome上传大文件(500 Mb)时,服务器正在提供system.OutOfMemoryException。 Internet Explorer is working fine. Internet Explorer工作正常。

Firefox 火狐

在此输入图像描述

Internet Explorer IE浏览器

在此输入图像描述

Chrome

在此输入图像描述

I don't know why it's different, but you can alter your behavior based on the browser (as opposed to standardizing as you asked in the question). 我不知道它为什么会有所不同,但你可以根据浏览器改变你的行为(而不是你在问题中提出的标准化)。

Refer to the code in the moo uploader as an example. 请参阅moo上传器中的代码作为示例。

From: https://github.com/juanparati/MooUpload/blob/master/Source/MooUpload.js 来自: https//github.com/juanparati/MooUpload/blob/master/Source/MooUpload.js

    // Get slice method
    if (file.mozSlice)          // Mozilla based
      chunk = file.mozSlice(start, total)
    else if (file.webkitSlice)  // Chrome, Safari, Konqueror and webkit based
      chunk = file.webkitSlice(start, total);
    else                        // Opera and other standards browsers
      chunk = file.slice(start, total)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM