简体   繁体   English

使用REST发送文件?

[英]Send file with REST?

Do Java REST frameworks like Restlet and Jersey allow one to send a file as input to a web service? Java REST框架(如Restlet和Jersey)是否允许将文件作为输入发送到Web服务?

This would encompass the client sending the file and the server then receiving and processing the file. 这将包括客户端发送文件和服务器然后接收并处理文件。

If you're asking if you can do an HTTP PUT to a Restlet service, then, absolutely, yes you can. 如果您询问是否可以对Restlet服务执行HTTP PUT,那么绝对可以。 You can use the Directory class if you just want to store the file, or you can implement your own ServerResource to handle the new resource. 如果只想存储文件,则可以使用Directory类,也可以实现自己的ServerResource来处理新资源。

I haven't used Jersey, but Restlet is a fantastic api. 我还没有使用Jersey,但是Restlet是很棒的api。

Well, there's no restriction for them not to do it. 好吧,没有限制让他们不这样做。 REST handles files without any problems. REST处理文件没有任何问题。 Take a look at: http://mikedesjardins.us/wordpress/2007/04/restful-services-on-ftp/ 看看: http : //mikedesjardins.us/wordpress/2007/04/restful-services-on-ftp/

You can also use REST Assured which builds on HTTP Client. 您还可以使用基于HTTP客户端构建的REST保证 It's very simple: 很简单:

given().multiPart(new File("/somedir/file.bin")).when().post("/fileUpload");

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

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