为什么 Javascript 上传块大小会随浏览器变化?

Why Javascript upload chunk sizes change by browser?(为什么 Javascript 上传块大小会随浏览器变化?)

本文介绍了为什么 Javascript 上传块大小会随浏览器变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 javascript 代码将文件上传到服务器.我注意到不同的浏览器发送不同大小的字节.如下图所示,Internet Explorer 发送的是小字节,而 Chrome 和 Firefox 发送的是更大的字节.

I am uploading files by javascript code to server. 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.

  1. 我正在使用 XMLHttpRequest 上传文件.我可以设定标准吗为所有浏览器上传字节?因为不同大小的流量给某些浏览器上的错误.Http 错误是 404.13.
  2. 我将 web.config 文件配置为 <requestLimits maxAllowedContentLength="1073741824">(1GB) 但是当我使用 Firefox 和 Chrome 上传一个大文件 (500 Mb) 时,服务器会给出system.OutOfMemoryException.Internet Explorer 运行良好.
  1. I am uploading files with 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.
  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. Internet Explorer is working fine.

火狐

Internet Explorer

推荐答案

我不知道为什么会有所不同,但是您可以根据浏览器更改您的行为(与您在问题中提出的标准化相反).

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

以moo上传器中的代码为例.

Refer to the code in the moo uploader as an example.

来自: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)

这篇关于为什么 Javascript 上传块大小会随浏览器变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:为什么 Javascript 上传块大小会随浏览器变化?

基础教程推荐