Image added through RestResource is not fully uploaded

I used this answer to make apex rest resource. It works perfectly for small images, but when I want to upload a bit larger image, the bottom part just gets cut.

I was trying to upload this picture, so I encoded it to base64 on this site and then used that Base64 string in my request.

Request went well and the image was attached, but when I preview it, I only see the top part of the image:

enter image description here

And when I look at the attachment details I see that this image is only 215Kb:

enter image description here

When I look at the same image on my machine it says that it is 1.1Mb:

enter image description here

So the question is:
What can be the reason of such behaviour?

Answer

As you already identified, some part of your data is lost somewhere.

I assume the Base64 encoded string gets cut somewhere because it doesn’t fit in a window, or field or editor or whatever, and then when you try to upload it, it only uploads a part (the first part) of the image. Due to the JPG format, it is still able to render the bytes that it did receive, i.e. the first part of the image.

So the ‘missing bottom part’ really is ‘the missing last part’ of the image and the cause probably is the uploaded Base64 string.

Attribution
Source : Link , Question Author : Novarg , Answer Author : Willem Mulder

Leave a Comment