how to get parameters' value from curl in REST web service in java
Do anyone know how to get parameters' values from curl command in REST web service using java.I have write a REST web service using jersey framework and java in NetBean IDE. This is my curl command to uplaod file without metadata:
curl -T C:UsersFoldersa.jpg -H "Content-Type:application/vnd.org.snia.cdmi.dataobject" http://localhost:8080/users/folder/a.jpg
This is my HttpPut method for upload
@PUT
@Path("/{directory:.+}")
public Response doPut(@PathParam("directory")String data,byte[]contents)
{
..............
}
This is my curl command to upload file with metadata
curl --data " { "metadata" : "Username":"name"}" -T C:UsersFoldersa.jpg -H "Content-Type:application/vnd.org.snia.cdmi.dataobject" http://localhost:8080/users/folder/a.jpg
This is my HttpPut method for upload
@PUT
@Path("/{direcotry:.+}")
public Response doPut(@PathParam("directory")String data,byte[]contents,String meta)
{
..............
}
My question is when i upload file without metadata i can upload successfully. But when i add metadata i can't get the "--data" values from curl command in doPut method. How can I solve it?
If you need to submit both a blob of binary data (the jpg) and some metadata (json string) in a single request, I'd recommend a request that submits a form (content type application/x-www-form-urlencoded
). This allows you to include both items in the request body.
Each item in the request is mapped to a method parameter using the @FormParam
annotation, so you'd have something like this:
@PUT
@Path("/{directory:.+}")
@Consumes("application/x-www-form-urlencoded")
public Response doPut(@PathParam("directory") String directory,
@FormParam byte[] image,
@FormParam String metadata) {
...
}
For details on how to continue testing this with curl, see the --data-urlencode
argument.
上一篇: REST设计用于文件上传