File upload via REST API results in corrupted file
janpetzold Nov 10, 2014 7:50 AMI'm using the (automatically deployed) REST API for Modeshape in Wildfly 8.1. I can upload plain text documents flawlessly, however when I upload a DOCX or PDF document the file becomes somehow "garbled" and I don't know why. Here's what I do:
Create a new node via upload call (POST):
http://localhost:8080/modeshape-rest/myrepo/default/upload/test/foo
I send the headers "Accept: application/json" and "Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document" which is the correct MIME type for DOCX.
I get a success response, once I browse my repo now I see the newly created node:
{ "self": "http://localhost:8080/myrepo/default/items/test/foo", "up": "http://localhost:8080/modeshape-rest/myrepo/default/items/foo", "id": "c85a656f-02b9-4d06-9828-652e47a9a51a", "jcr:primaryType": "nt:file", "jcr:created": "2014-11-10T13:36:00.705+01:00", "children": {"jcr:content": { "self": "http://localhost:8080/modeshape-rest/myrepo/default/items/test/foo/jcr%3acontent", "up": "http://localhost:8080/modeshape-rest/myrepo/default/items/test/foo", "id": "f9523a32-4d27-444c-be8b-0ab63261178b" }} }
The jcr:content looks like this:
{ "self": "http://localhost:8080/modeshape-rest/myrepo/default/items/test/foo/jcr%3acontent", "up": "http://localhost:8080/modeshape-rest/myrepo/default/items/test/foo", "id": "f9523a32-4d27-444c-be8b-0ab63261178b", "jcr:primaryType": "nt:resource", "jcr:data": "http://localhost:8080/modeshape-rest/myrepo/default/binary/test/foo/jcr%3acontent/jcr%3adata", "jcr:lastModified": "2014-11-10T13:43:34.646+01:00", "jcr:lastModifiedBy": "xxx", "jcr:mimeType": "application/zip" }
Now the MIME type is set to application/zip, which is weird, but not necessarily wrong since DOCX is essentially a zipped document. However when I download the file via /binary it is not decompressable and also renaming it to DOCX results in a broken file. What is wrong here?
Same happens for PDF - I can download the file but it displays nothing but blank pages.