Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Add attachment file to document using REST View modes: 
User avatar
Member
Member
tomasz.rutecki+kentico.com-gmail - 2/12/2013 9:52:47 AM
   
Add attachment file to document using REST
Hello,

I have one question about creating documents using REST integration. How to add a new document with attachment file? Can you send me a example request?

Thanks in advance

User avatar
Member
Member
kentico_davidb2 - 2/14/2013 3:49:03 AM
   
RE:Add attachment file to document using REST
Hello

You need to perform two requests:

Firstly, you need to create your document:
POST http://localhost/7/rest/content/site/CorporateSite/en-us/document/Extras2 HTTP/1.1
User-Agent: Fiddler
Authorization: Basic YWRtaW5pc3RyYXRvcjo=
Host: localhost
Content-Type: text\xml
Content-Length: 151

<CMS_MenuItem><NodeClassID>3470</NodeClassID><DocumentName>aaaRestTest</DocumentName><DocumentPageTemplateID>79</DocumentPageTemplateID></CMS_MenuItem>

This will return the DocumentID needed for next step.

Then you need to create the attachment:
POST http://localhost/7/rest/cms.attachment HTTP/1.1
User-Agent: Fiddler
Authorization: Basic YWRtaW5pc3RyYXRvcjo=
Host: localhost
Content-Type: text\xml
Content-Length: 3305

<data>
<cms_attachment>
<AttachmentMimeType>image/png</AttachmentMimeType>
<AttachmentSize>2110</AttachmentSize>
<AttachmentExtension>.png</AttachmentExtension>
<AttachmentName>TestAttachment.png</AttachmentName>
<AttachmentDocumentID>694</AttachmentDocumentID>
<AttachmentIsUnsorted>True</AttachmentIsUnsorted>
<AttachmentImageWidth>32</AttachmentImageWidth>
<AttachmentImageHeight>32</AttachmentImageHeight>
<AttachmentBinary>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAIBUlEQVR42qWXe1AV1x3Hf2f37n3yRgMqoFe5cHld4CKRa4qQSZN2nMlo/7Cdaaa1bYxvnWLapGnTZtom1ukfTZrmdUNT6zidydTpREwmkyZpEkABechDQAUaQUDEiLy5r330t2d3r7uInYSc4XL23j17fp/z/T3OWQKL2rPV3UUm1rQNgDijP0oSgeU2QiT1aogXIu89/0R+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ppSfM1rlYUBDwroGHc/zlGgtQkCzjX2ND4KFhhst9lPfc0PtEhA6xEgCxeMj8wFPLs3nx/4Qa6Wv0uGE1DfSoy0U1KUmzTgqNASHdfyy7A/lxz92Aa21ptZoL1ONcV+UzowBEp+CUX+9xJPrVsTkxx8WCNQTC6NM0VesNKub6zbVNDMoWoyC2/G0miQJ2CFxIjBRYc5EZ/AjPciGN7BUG4hKeuMXL48GETNkcoFJK3M/mNOA0NJ+P5zU6o02H5b8ZKwx2cCGg0gP0EzjuMp6xBBBhHO/PE7XaT8vJyNhKJWOOw8TyfiDficbAVH2Lxga8FgHNRAJxHfuGcxjknOY6bxhZsamoS/geO3rftfjG8IgAAAABJRU5ErkJggg==
</AttachmentBinary>
</cms_attachment>
</data>

David

User avatar
Member
Member
tomasz.rutecki+kentico.com-gmail - 2/14/2013 9:18:56 AM
   
RE:Add attachment file to document using REST
It doesn’t work with documents under workflow. It’s fine when workflow is off.

User avatar
Member
Member
kentico_davidb2 - 2/19/2013 9:17:48 AM
   
RE:Add attachment file to document using REST
Hello,

could you please be more specific about your issue?

By document being under workflow you mean that a workflow is set or that it needs to be at a specific step?

Also, could you please describe what you mean by not working? Are you getting any response? Is anything logged within Event log? Are you getting any error message anywhere?

Thank you in advance for more information.

David