简体   繁体   English

JavaScript文件上传参差不齐

[英]JavaScript file upload is spotty

I have some code that uses the HTML input file type to upload XSL to a server-side program. 我有一些使用HTML输入文件类型的代码将XSL上传到服务器端程序。 While it works most of the time, once in a while the submit button will return with "The connection was reset," and my server will not have gotten anything (nothing was posted). 在大多数情况下,提交按钮有时会返回“连接已重置”,并且我的服务器什么也没得到(什么都没张贴)。 Here's the code for the file upload, it's pretty standard: 这是文件上传的代码,这很标准:

<form action="upload.htm" method="POST" enctype="multipart/form-data" encoding="multipart/form-data">
<input type="file" id="datafile" onchange="checkFileType(this.value)" /><br/>
<input type="submit" id="datasubmit" value="Send" onclick="submitConfirm()" disabled />
</form>

checkFileType will enable and disable the submit button according to filetype, and submitConfirm just hides the form and shows a div containing "Uploading...". checkFileType将根据文件类型启用和禁用“提交”按钮, submitConfirm只是隐藏表单并显示一个包含“ Uploading ...”的div

I may be entirely off with this, but I have found that using an XSL file that's larger (60kb) will fail every single time, whereas my original tests with a small file (15kb) worked every time. 我可能对此完全不满意,但是我发现使用较大(60kb)的XSL文件每次都会失败,而使用小文件(15kb)的原始测试每次都可以工作。 Is there a size limit to uploading, or is there something I'm missing? 上传是否有大小限制,或者我缺少什么?

Edit: Also, just to throw it out there, the other case I the file upload to fail consistently with was when I tried to upload non-XSL files (before I implemented the checkFileType function). 编辑:另外,只是把它扔在那里,另一种情况是文件上传始终失败,是当我尝试上传非XSL文件时(在实现checkFileType函数之前)。 These non-XSL files were mostly shortcuts, so less than 10kb. 这些非XSL文件大多是快捷方式,因此少于10kb。

What are you using for your web server? 您正在使用什么作为Web服务器? The web server may have a limit on uploaded file size. Web服务器可能对上传的文件大小有限制。 I know that in IIS + ASP.NET, that limit had to be changed. 我知道在IIS + ASP.NET中,必须更改该限制。

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

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