Attachment created using rest api not opening in system/file/attachment in administration

ravi yadav asked on February 9, 2023 10:16

Hi there I am after some advice for the correct format for sending a request to Kentico REST for creating a CMS.Attachment object. I have followed the instructions at the below link:

https://docs.kentico.com/k81/integrating-3rd-party-systems/kentico-rest-service/manipulating-data-using-rest

i am getting 201 created but when i am checking attachment in system/file/attachment its not opening

I am using .Net and populating the above attribute with Convert.ToBase64String(loAttachmentBinary) where loAttachmentBinary is a Byte() object of the source PDF file.

Correct Answer

Not Applicable answered on February 9, 2023 15:20

You can check if the Base64 AttachmentBinary value in the XML is valid by decoding it on this website: https://base64.guru/converter/decode/pdf. It should display the PDF correctly.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Not Applicable answered on February 9, 2023 12:53 (last edited on February 9, 2023 13:00)

This should work, at least with Kentico 13. Check that you have the whole base64 string and correct file size. Do you have the correct version of the documentation (you're linking to 8.1)?

var filename = @"C:\test.pdf";
var file = System.IO.File.ReadAllBytes(filename);
Convert.ToBase64String(file); // AttachmentBinary
var fileInfo = new FileInfo(filename); 
fileInfo.Length; // AttachmentSize
0 votesVote for this answer Mark as a Correct answer

ravi yadav answered on February 9, 2023 13:20 (last edited on February 9, 2023 13:53)

        model.AttachmentName = "Agenda-1-March-2020.pdf";
        model.AttachmentMimeType = "application/pdf";
        model.AttachmentExtension = ".pdf";

        var filename = @"D:\Live Projects\Agenda-1-March-2020.pdf";
        var file = System.IO.File.ReadAllBytes(filename);
        model.AttachmentBinary =Convert.ToBase64String(file); // AttachmentBinary
        var fileInfo = new FileInfo(filename);


        model.AttachmentSize=fileInfo.Length.ToString(); // AttachmentSize`text`

Still Not Working Sir

0 votesVote for this answer Mark as a Correct answer

Not Applicable answered on February 9, 2023 14:08

You create the XML request body from the model? Is the uploaded file stored in database or filesystem?

0 votesVote for this answer Mark as a Correct answer

ravi yadav answered on February 9, 2023 14:23 (last edited on February 9, 2023 14:23)

Yes I create the XML request body from the model and file storing only in database

0 votesVote for this answer Mark as a Correct answer

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