I am trying to put application/octet-stream HttpResponse body to a .zip file (ContentVersion).

I am doing it like this:

insert new ContentVersion(
    Title = title, 
    PathOnClient = title + '.zip', 
    ContentLocation = 'S', 
    VersionData = Blob.valueOf(res.getBody())

The file is created, but when I am trying to download it and extract it throws an error (2 types of errors actually): enter image description here enter image description here

Just to mention: when I am trying to use the same request in postman and click Save response to file, the archive can be unzipped.

Please, point out what I am missing.

1 Answer 1


I found a solution, not deleting question, because it may be helpful for others:

Use res.getBodyAsBlob() instead of Blob.valueOf(res.getBody()).

  • 1
    The reason why, by the way, is that getBody coerces the binary data into a Unicode string, which results in the loss or corruption of binary data.
    – sfdcfox
    Apr 19 at 12:13

You must log in to answer this question.

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