简体   繁体   English

ASP.NET Web服务损坏了上传的文件

[英]ASP.NET Webservice corrupts uploaded file

I have a webservice through which I can upload documents to our ASP.NET web site. 我有一个Web服务,通​​过它可以将文档上传到我们的ASP.NET网站。 The problem is when I upload PDF & word documents, they get corrupted when I try to open them. 问题是当我上传PDF和Word文档时,当我尝试打开它们时它们会损坏。 Text documents always upload fine. 文本文档总是可以上传。 What is even strange is that on my development machine, these files upload fine but when I try to upload to our demo site, they get corrupted. 甚至奇怪的是,在我的开发计算机上,这些文件可以很好地上传,但是当我尝试上传到我们的演示站点时,它们会损坏。

Any ideas? 有任何想法吗?

my code is of the format: 我的代码格式如下:

WebServicesSoapClient proxy = new WebServicesSoapClient();

byte[] data = GetFileByteStream("C:\\temp\\sample.pdf");
string response = proxy.UploadDocument("james", "password", 
                         orderId, "Sample.pdf", data, true);

Are your pdf files larger than 4MB? 您的pdf文件是否大于4MB? That is the default maximum request length for ASP.NET. 这是ASP.NET的默认最大请求长度。 You can override that setting in your web.config with: 您可以使用以下方法在web.config中覆盖该设置:

<httpRuntime maxRequestLength="8192" />

However, be aware that this will increase your memory usage on your server - by default asp.net will cache the entire request in memory. 但是,请注意,这会增加服务器上的内存使用率-默认情况下,asp.net会将整个请求缓存在内存中。

Also, I'm not entirely certain this is the problem in your case, since normally this exceeding the request length would cause an exception to be thrown - not silent file corruption. 另外,我也不完全确定这是您的问题所在,因为通常情况下,超出请求长度会导致引发异常-而不是无声文件损坏。

see also http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626 另请参见http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626

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

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