On Feb 10, 2010, at 1:00 AM, Radek Rekas wrote:
I'm having trouble finding out how to upload attachments using the RESTful api.
I've looked at the attachment type in the schema (http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rest/src/main/r...) but I cant find any mention of how to link the actual attachment data.
Also none of the xml resource representations are loading, I keep getting 404 errors: http://www.xwiki.org/rel/attachmentDatahttp://www.xwiki.org/rel/attachments
Can anyone provide any tips on how to upload an attachment to a page using the restful api?
Thanks,
Hi Radek, in order to upload an attachment to a page wiki:space.page you must do an HTTP PUT on the http://server/xwiki/rest/wikis/{wiki}/spaces/{space}/pages/{page}/attachments/{attachmentName} with the body of the request containing the attachment data. The attached file in the page will have the name you specify in the {attachmentName} part of your URI. For example, using curl, you can upload a file main.pdf to the Main.WebHome using the following command: $ curl -u Admin:admin -T path_to/main.pdf http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/attac... If you open the Main.WebHome page you will see that a file foo.pdf is attached to the page and the content is that of your original main.pdf. The request authenticates you as Admin. The response, if the upload is successful, is a 201 - CREATED response whose body is the XML described in the REST XSD's model containing all the information about the newly created attachment. If the attachment already exists then a 202 - ACCEPTED response code is returned. The response's body contains the same type of XML. Cheers, Fabio