ASMX文件上传
有没有办法使用 ASMX Web 服务将文件从本地文件系统上传到服务器中的文件夹(没有 WCF,不要问为什么:)?
UPD
PS文件大小可以是 2-10 GB
Is there a way to upload a file from local filesystem to a folder in a server using ASMX web services(no WCF, don't ask why:)?
UPD
P.S.file size can be 2-10 GB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当然:
然后公开服务,从 WSDL 生成客户端代理,调用标准内容。
--
更新:
我现在看到您关于处理大文件的更新。 WCF 中内置的带流的 MTOM 协议针对处理此类问题进行了优化场景。
Sure:
then expose the service, generate a client proxy from the WSDL, invoke, standard stuff.
--
UPDATE:
I see your update now about handling large files. The MTOM protocol with streaming which is built into WCF is optimized for handling such scenarios.
在开发将大文件上传到服务器的免费工具时,我还使用 .NET 2.0 和 Web 服务。
为了使应用程序对非常大的文件具有更强的容错能力,我决定不上传一个大的
byte[]
数组,而是进行“分块”上传。例如,为了上传 1 MB 文件,我确实调用了上传 SOAP 函数 20 次,每次调用都会传递一个 50 KB 的
byte[]
数组,并再次在服务器上将其连接在一起。我也会数包裹,当一个包裹掉下来时,我会多次尝试重新上传。
这使得上传的容错能力更强,并且 UI 的响应速度更快。
如果您有兴趣,这是该工具的CP文章。
When developing my free tool to upload large files to a server, I am also using .NET 2.0 and web services.
To make the application more error tolerant for very large files, I decided to not upload one large
byte[]
array but instead do a "chuncked" upload.I.e. for uploading a 1 MB file, I do call my upload SOAP function 20 times, each call passing a
byte[]
array of 50 KB and concating it on the server together again.I also count the packages, when one drops, I try to upload it again for several times.
This makes the upload more error tolerant and more responsive in the UI.
If you are interested, this is a CP article of the tool.
对于非常大的文件,将它们发送到 Web 服务的唯一有效方法是使用 MTOM 。并且 MTOM 仅在 WCF 中受支持,您已排除了这一点。使用旧式 .asmx Web 服务执行此操作的唯一方法是 @Darin Dimitrov 给出的答案。使用该解决方案,您将不得不承受文件进行 Base64 编码的成本(带宽增加 33%)。
For very large files, the only efficient way to send them to web services is with MTOM. And MTOM is only supported in WCF, which you have ruled out. The only way to do this with old-style .asmx web services is the answer that @Darin Dimitrov gave. And with that solution, you'll have to suffer the cost of the file being base64 encoded (33% more bandwidth).
我们有相同的要求,基本上是使用客户端的标准
FileUpload
控件通过 HTTP POST 上传文件。最后,我们只是向 ASMX Web 服务项目添加了一个 ASPX 页面(毕竟它只是一个 Web 项目)——这允许我们上传到 ie
http://foo/bar/Upload.aspx
当 Web 服务位于http://foo/bar/baz.asmx
时。这保留了 Web 服务中的功能,即使它使用单独的网页。这可能符合也可能不符合您的要求,@Darins 方法也可以作为一种解决方法,但您必须为此在客户端进行修改,这对我们来说不是一个选择。
We had the same requirement, basically uploading a file via HTTP POST using the standard
FileUpload
controls on the client side.In the end we just added an ASPX page to the ASMX web service project (after all its just a web project) - this allowed us to upload to i.e.
http://foo/bar/Upload.aspx
when the web service was athttp://foo/bar/baz.asmx
. This kept the functionality within the web service, even though it was using a separate web page.This might or might not fit your requirements, @Darins approach would work as a workaround as well but you would have to make modifications on the client side for that, which wasn't an option for us.
您可以尝试将文件转换为 Base64 并将其作为字符串传递给服务,然后转换回字节数组。
https:// forums.asp.net/t/1980031.aspx?Web+Service+method+with+Byte+array+parameter+throws+ArgumentException
如何在 JavaScript 中将文件转换为 base64?
输入不是有效的 Base-64 字符串,因为它包含非 Base 64字符
You can try to convert the file to Base64 and pass it as a string to the service and then convert back to a byte array.
https://forums.asp.net/t/1980031.aspx?Web+Service+method+with+Byte+array+parameter+throws+ArgumentException
How to convert file to base64 in JavaScript?
The input is not a valid Base-64 string as it contains a non-base 64 character