+

Search Tips   |   Advanced Search

REST: Attachments

We can use the REST service to attach images to some item types. This is equivalent to using the Insert An Image button in the authoring portlet.

An attachment is an image resource associated with another item containing HTML, and can be referenced from within that item. Attachments are a special kind of item in the REST service because they cannot be directly referenced. This is because there is no URI associated with an attachment once it is created. Due to this, an attachment cannot be read or updated, but can be deleted indirectly by performing an update on the parent item.

Attachments can be added to the following item types:

Create the item containing a rich text or HTML element before creating the attachment.


Creating

/ITEM-TYPE/ITEM-UUID/attachments
Content-Type: image/*

When creating an attachment, the binary data, but not encoding, of an image is sent to the attachments collection of an item. The Content-Type header field is set to the appropriate image type. For example: image/jpg, image/png

Example:

HTTP/1.1 POST 
http://host:port/wps/mycontenthandler/wcmrest/LibraryHTMLComponent/ITEM-UUID/attachments
Content-Type: image/jpg
(… binary data … )

201 Created


Reading

Not supported.


Updating

Not supported.


Deleting

An attachment cannot be directly referenced through the REST service, which means it cannot be directly deleted. However, it can be deleted indirectly by performing an update operation on the parent item. For example, this is some markup stored in a HTML component:
<h1> Example Delete </h1>
<img src='/wps/myconnect/65132264-fd8b-461c-b6ec-ccdd22524ea6/image.jpg?MOD=AJPERES'
 alt='' title='' border='0'  />

To remove the image, we would make the following update request:

HTTP/1.1 PUT 
http://host:port/wps/mycontenthandler/wcmrest/LibraryHTMLComponent/ITEM-UUID/
Content-Type: text/html

<h1> Example Delete </h1>

200 OK


Parent: Work with web content items using REST