On Wed, Feb 13, 2013 at 6:05 PM, zacharykane <kane.zach(a)gmail.com> wrote:
Hello, I'm trying to create an attachment on a
page from a URL to an image,
using JavaScript and the RESTful API.
I'm not sure I'm doing it correctly of if this can be done but here's where
I'm at:
httpRequest.open('PUT', '/xwiki/rest/wikis/XWiki/spaces/Main/pages/Daily
All-Source Digest – 2013-01-05T07:30P24/attachments/Blade Header
UnClassified-S.png');
I think the following is wrong. You just have to send (PUT) the actual
PNG data using application/octet-stream media type and that's it. No
XML involved here.
httpRequest.setRequestHeader('Content-Type',
'application/xml');
httpRequest.send('<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><attachment
xmlns="http://www.xwiki.org"><name>"Blade
Header
UnClassified-S.png"</name><mimeType>"image/png"</mimeType><xwikiAbsoluteUrl>"https://domain/xwiki/bin/download/ColorThemes/Nightfall/Blade%20Header%20UnClassified-S.png"</xwikiAbsoluteUrl></attachment>');
This example is actually using a URL to a preexisting Attachment, just
seeing if I'm getting permission errors on the server some how. I've also
tried random publicly accessible images.
I get a 200 response signaling an attachment is created and a link appears
on the page in the attachment section but the image won't display because
'it contains errors'.
Can I submit attachments this way? Do I need the actual image data, encoded
somehow?
What you did, instead, is to send XML as PNG data, that's why your
file is seen as corrupted. You didn't send any actual PNG bytes.
Let me know if it works
-Fabio