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?

  • is it happening with all images? Sep 3, 2015 at 9:46
  • try uploading multiple images of different sizes. Sep 3, 2015 at 9:47
  • @AtulRajguru9 yes, I tried some other images and some of them also get cut. I didn't check their size however
    – Novarg
    Sep 3, 2015 at 9:47
  • Try with different image. If happening the same then you will have to post the snippet which does the encoding, sending and attaching.
    – Ashwani
    Sep 3, 2015 at 9:47

1 Answer 1


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.

  • 3
    Hi Willem, thanks for you answer, it did push me in the right direction. I didn't know about the JPG format possibility of showing only the first part, so I thought that it's some undocumented limitation of Salesforce. However, it appears that the encoder I was using only gave me ~215kb, so the problem was with this Base64 string. When I used another encoder I could successfully upload images of +-2mb.
    – Novarg
    Sep 3, 2015 at 14:06

You must log in to answer this question.

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