简体   繁体   English

将文件上传到Web服务(java)

[英]Upload file to webservice (java)

I am looking for a solution to upload a file from a client to a server connected through a web service. 我正在寻找一种解决方案,将文件从客户端上传到通过Web服务连接的服务器。 The client is written in c# and the web Service in java. 客户端用c#编写,Web Service用Java编写。 The files can be rather large < 100MB. 这些文件可能会小于100 MB。

What approach would you suggest is best ? 您认为哪种方法最好?

Base64 encode the file and send it as an attachment. Base64对文件进行编码并将其作为附件发送。 If you need to make sure the contents of the attachment do not get changed en route, use MTOM. 如果您需要确保附件的内容在途中没有被更改,请使用MTOM。 Otherwise, use DIME. 否则,请使用DIME。

Agree an encoding on both client and server then serialize the file using that encoding, wrap it in CDATA tags and assign the value to a text node in your SOAP request on the client. 同意客户端和服务器上的编码,然后使用该编码对文件进行序列化,将其包装在CDATA标记中,然后将值分配给客户端上SOAP请求中的文本节点。

Read the data between the CDATA tags on the server, deserialize it using the agreed encoding and you'll have the byte stream to use as need be. 读取服务器上CDATA标记之间的数据,使用约定的编码对数据进行反序列化,然后将根据需要使用字节流。

It's probably a good idea for the encoding to involve some sort of compression if the files are large, although be wary of interop issues if the client is .NET and the server Java. 如果文件很大,则编码涉及某种压缩可能是一个好主意,但是如果客户端是.NET和服务器Java,则要警惕互操作问题。

对于服务器端,您应该看看Commons File Upload

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

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