开发者

Upload data method in REST web service

Do anyone know how can I write POST method in RESTful web service to upload data using java ? I found that开发者_Go百科 smartupload and commons.upload are just for web page.


You can use some JAX-RS library, like Apache Wink, so you can write something like this:

@Path("/upload")
class UploadResource {

    @POST
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    public Response upload(byte[] input) {
        // store input somewhere
        return Response.ok().build();
    }

}

So you will receieve your file is byte[]. You can also receive as InputStream:

@Path("/upload")
class UploadResource {

    @POST
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    public Response upload(InputStream input) {
        // store input somewhere
        return Response.ok().build();
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜