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();
}
}
精彩评论