0

I have a boomi process which takes the file content and send it to salesforce to create attachment. But attachment is blank.

Here is my code:

String jsonStr = 'iVBORw0KGgoAAAANSUhEUgAABo4AAAMgCAYAAAAdtpBIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAP+lSURBVHhe7P15dFRXnub9qv6447p/9Fq3V+aq9d57q7vve7u6K7s6q1z9ZnWnszOd2W47M92Zdk52OT2nZ4zxANgYbAwGbAy2Gcw8GMw8g5kHM8/zIECMEgIJxCjmGf9uPFuxxVHElhQKhRQh6fhBBCCCGEEEIIIYQQQgghzSNVi6PnIx8TE7s9tAJCCCGEEEIIIYQQQgghhBDSPJL3b5//2v7tCxXT0bnPn';
Attachment attach = new Attachment();
attach.contentType = 'image/png';
attach.name = 'test.png';
attach.parentId = '0010H00002DW2Ds';
attach.body = EncodingUtil.base64Decode(jsonStr);
insert attach;

Attachment is inserted but there is no content inside. Is there anything I am doing wrong.

Thank you, Thiru

5
  • What is the File type here?
    – Saroj Bera
    Commented Mar 8, 2023 at 7:48
  • 1
    I have answered a similar question here, please check salesforce.stackexchange.com/questions/180211/…
    – Saroj Bera
    Commented Mar 8, 2023 at 7:49
  • 1
    As I see the base64 is of the image, so you need to set the file type as 'image/png' att.contentType = 'image/png'; Commented Mar 8, 2023 at 7:51
  • I have updated my new code in my question. But its still showing empty content. may be my base64 data is wrong.? I took the content from already attached image. Attachment atts = [SELECT ID,Body,ContentType FROM Attachment WHERE ID = '00Pp000000FskcuEAB']; String body1 = EncodingUtil.base64Encode(atts.Body); Commented Mar 8, 2023 at 8:13
  • Thank you @Saroj Bera Commented Mar 9, 2023 at 1:57

1 Answer 1

2

This file looks like a legitimate PNG file fragment when saved and downloaded. Reading through the file, we see:

tag length data
Magic 8 iVBORw0KGgo= // PNG HEADER
IHDR 13 Width = 1678, Height = 800, Bit Depth = 8, Color Type = 6, Compression Method = 0, Filter Method = 0, Interlace Method = 0
sRGB 1 0
gAMA 4 45455
pHYS 9 X = 5669, Y = 5669, Unit = Meters
IDAT 255 Pixel data 165 bytes long

Here the file trails off. There should be an IEND specifying the end of the image, but it doesn't exist. My conclusion is that the file is a fragment of what would be a valid PNG, but the rest of the file is missing.

1
  • Its working finally. The body content was invalid Commented Mar 9, 2023 at 1:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .