ASP.NET Web 服务损坏上传的文件
我有一个 Web 服务,通过它我可以将文档上传到我们的 ASP.NET 网站。 问题是当我上传 PDF 和 Word 文档,当我尝试打开它们时,它们被损坏了。 文本文档总是可以正常上传。 甚至奇怪的是,在我的开发计算机上,这些文件上传正常,但当我尝试上传到我们的演示站点时,它们被损坏了。
有任何想法吗?
我的代码的格式为:
WebServicesSoapClient proxy = new WebServicesSoapClient();
byte[] data = GetFileByteStream("C:\\temp\\sample.pdf");
string response = proxy.UploadDocument("james", "password",
orderId, "Sample.pdf", data, true);
I have a webservice through which I can upload documents to our ASP.NET web site.
The problem is when I upload PDF & word documents, they get corrupted when I try to open them. 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 pdf 文件是否大于 4MB? 这是 ASP.NET 的默认最大请求长度。 您可以通过以下方式覆盖 web.config 中的该设置:
但是,请注意,这会增加服务器上的内存使用量 - 默认情况下,asp.net 会将整个请求缓存在内存中。
另外,我不完全确定这就是您的情况的问题,因为通常超过请求长度会导致抛出异常 - 而不是静默文件损坏。
另请参阅 http://support.microsoft.com/default。 aspx?scid=kb;EN-US;295626
Are your pdf files larger than 4MB? That is the default maximum request length for ASP.NET. You can override that setting in your web.config with:
However, be aware that this will increase your memory usage on your server - by default asp.net will cache the entire request in memory.
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