2013-10-11 34 views
5

我正在通过JavaScript代码上传文件到服务器。我注意到不同的浏览器正在发送不同大小的字节。正如您在下面的图片中看到的,Internet Explorer发送的是小字节,但Chrome和Firefox发送更大的字节。为什么Javascript通过浏览器上传块大小?

  1. 我使用XMLHttpRequest上传文件。我可以为所有浏览器设置标准的 上传字节吗?因为不同大小的流量在某些浏览器上给出了 错误。 Http错误是404.13。
  2. 我将web.config文件配置为<requestLimits maxAllowedContentLength="1073741824">(1GB),但是当我使用Firefox和Chrome上传大文件(500 Mb)时,服务器发出system.OutOfMemoryException。 Internet Explorer工作正常。

火狐

enter image description here

的Internet Explorer

enter image description here

enter image description here

+1

复制? http://stackoverflow.com/questions/19332692/does-javascript-features-change-by-browser –

回答

1

我不知道为什么它不同,但是你可以根据浏览器改变你的行为(与你在问题中提出的标准化相反)。

请参考moo uploader中的代码作为例子。

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