I'm trying to upload files to a web service using curl, then save those files in a database. It's working well so far for text files, but pictures are corrupted.
So let's say I'm uploading the file logo.png using curl :
curl -T D:\logo.png http://127.0.0.1:8080/my-web-service/resteasy/document/metadata?id=logo"&"contentType=IMAGE"&"httpType=image"/"png
My webservice consumes the data like this:
@Path("metadata")
@PUT
public void putDocument(
@QueryParam("id") String docId,
@DefaultValue("GENERIC_CONTENT") @QueryParam("contentType") String contentType,
@DefaultValue("text/html") @QueryParam("httpType") String httpType,
byte[] docContent) {
Document doc = new Document();
doc.setDocumentId(docId);
doc.setContentType(new RefContentType(ContentType.valueOf(contentType)));
doc.setHttpContentType(httpType);
doc.setContent(docContent);
doc = getDAO().save(doc);
LOG.info("Document saved successfully id : " + doc.getId());
So my best guess is that the setContent method doesn't work well with a byte array containing something other than plain text. How can I know if curl is messing the upload or if it's my ejb that reads the array badly?
Thanks for your help.