page type field attachment not updating

ravi yadav asked on February 10, 2023 09:13

i am creating attachment with documentId and attachmentGroupGuid but attachment not visible in page field but attachment creating successfully

page type filed data type is attachments

Correct Answer

Juraj Ondrus answered on February 14, 2023 08:00

I am using Kentico 13, no workflow and the POST request works fine. The REST API call URL is like: https://domain.com/rest/cms.attachment/currentsite
and the request body XML is:

<CMS_Attachment>
  <AttachmentName>NewAttachmentFile2.png</AttachmentName>
  <AttachmentExtension>.jpg</AttachmentExtension>
  <AttachmentSize>File Size in Bytes</AttachmentSize>
  <AttachmentMimeType>image/x-jpg</AttachmentMimeType>
  <AttachmentImageWidth>183</AttachmentImageWidth>
  <AttachmentImageHeight>47</AttachmentImageHeight>
  <AttachmentDocumentID>192</AttachmentDocumentID>
  <AttachmentGroupGUID>Attachment Field GUID</AttachmentGroupGUID>
  <AttachmentBinary>base64 encoded binarey data</AttachmentBinary>
</CMS_Attachment>  

You need to change the AttachmentSize value to the actual file size in bytes, use appropriate AttachmentDocumentID, AttachmentGroupID - this is the attachments field GUID and also set the right base64 string for the binary data.
I just tested the above and works perfectly fine. I used this tool to get the base64 string

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on February 10, 2023 16:09

Have you reviewed the Attachments API Examples? I'd suggest starting with that first and see if this helps you.

0 votesVote for this answer Mark as a Correct answer

ravi yadav answered on February 13, 2023 06:06

I am using rest api for creating attachment and i am not retrieving page but when i am checking page's form tag attachment is not visible

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 13, 2023 09:24

What is the field type you are using in your page type? It is an uploader field? It is page attachment field? Or, when you check Properties -> Attachments, do you see the attachment there? There is a difference in attachment types - file upload vs grouped vs unsorted attachment.

0 votesVote for this answer Mark as a Correct answer

ravi yadav answered on February 13, 2023 10:48

i am using attachment as field type and no there is no attachment in properties -> attachment.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 13, 2023 12:12

So, in this case you are using grouped attachments and you should be using API like this. Make sure you are setting the right field GUID. And also,if you are using workflows, make sure you are editing the right version - the admin UI displays the latest edited version while the live site the latest published version. And sometimes the edited version is not the same as published version. See how the content and attachments are stored in the DB too.

0 votesVote for this answer Mark as a Correct answer

ravi yadav answered on February 13, 2023 12:53

sir i am using kentico rest api to create attachment. and i checked field guid.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 13, 2023 13:07

So, how does the POST request looks like? Are you setting all the properties correctly? How are you passing the data? Is it base64? So I assume you are not using workflows. After you post the attachment, do you also update the value in the page's field to contain the attachment GUID?
If you check the DB tables, how the content is stored - do you see the attachment record in the CMS_Attachment table? Are the data set correctly? What happens when you restart the Kentico app?

0 votesVote for this answer Mark as a Correct answer

ravi yadav answered on February 13, 2023 13:51 (last edited on February 14, 2023 06:43)

i am using base url + "/cms.attachment/currentsite". yes it is base64 and also stored curraclty in to database. and i am also using work flow.

properties that i used:-

    public Guid AttachmentGroupGUID { get; set; }
    public string AttachmentName { get; set; }
    public string AttachmentExtension { get; set; }
    public string AttachmentSize { get; set; }
    public string AttachmentMimeType { get; set; }
    public int AttachmentDocumentID { get; set; }
    public string AttachmentBinary { get; set; }

After i post the attachment, i do not update the value in the page's field to contain the attachment GUID. nothing happen restarting application

and also can you tell me is there any way that i can make a new version of that page using rest API

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.