开发者

Upload data method in REST web service

开发者 https://www.devze.com 2023-02-21 03:33 出处:网络
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 lib

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

精彩评论

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