I'm developing an file (attachments/contents) upload app and the process of my upload is that I upload file in chunks to ensure I'm not hitting view state.

For first chunk

insert new attachment

insert new Attachment att = new Attachment(ParentId = parentId,Body = EncodingUtil.Base64Decode(base64BlobValue),Name = fileName, ContentType = contentType);

For remaining chunks

update above uploaded new attachment ie Take the body of the current attachment, convert to base64 string, append base64 value sent from page, then convert back to binary for the body

for(Attachment atm : [select Id, Body from Attachment where Id = :attachmentId]){
                update new Attachment(Id = attachmentId, Body = EncodingUtil.Base64Decode(EncodingUtil.Base64Encode(atm.Body) + base64BlobValue));

This is working great for Attachments, but when I apply same mechanism for CONTENT (ie ContentVersion) its not working as expected. ContentVersion file body (versiondata) always stores last chunk data only ie its not *APPENDING.*

For First chunk

        insert new ContentVersion(
            versionData = EncodingUtil.Base64Decode(base64BlobValue),
            Title = fileName,
            PathOnClient = '/'+fileName,
            FirstPublishLocationId = libraryId);

For rest chunks

    for(ContentVersion atm : [select Id, VersionData from contentversion where Id = :contentId]){
        update new ContentVersion(
           Id = contentId, 
           VersionData = EncodingUtil.Base64Decode(EncodingUtil.Base64Encode(atm.versionData) + base64BlobValue));

Possible Issue : Body field of Attachment is Creatable and Updatable, whereas VersionData field of ContentVersion is Creatable and Nillable (and NOT Updatable).

Any clue or suggestion, please!


4 Answers 4


As you mention ContentVersion is not updatable (versions are explicitly immutable, a feature of the content product), you would have to stage the blob somewhere else (perhaps an attachment) until its complete, then create the contentVersion record.

  • 1
    sounds like a good workaround, and immutable sounds like a must have for content product. This clears my doubt on why its not editable/updatable. Thank you! Commented Aug 21, 2012 at 20:17
  • Just realized one thing, this will limit me to allow upload via my app to 5MB only -:( as I will have to use Attachment or Document to store which supports 5MB as max size. Any workarounds to support big file size? Commented Aug 22, 2012 at 9:00
  • I'm not exactly sure why you even need to chunk it up to start with.
    – superfell
    Commented Aug 22, 2012 at 14:58
  • The reason is to handle view state. Also please note I'm not using input type file or apex:inputfile, I'm trying to use HTML5 drag and drop to upload files, so it has to be in chunks :) Commented Aug 22, 2012 at 19:38

I think that your right, there is no way to update the ContentVersion.VersionData field.

However, there is a versioning system, where you might be able to sequentially use the ContentDocument to create new versions of the document each with the additional data added to the end.

You can also create a ContentVersion record and have the same ContentDocumentId so that it becomes different versions of same content and the version history will be automatically maintained.

  • 1
    That's sad! (unable to locate emoticons in stackexchange?) Creating new versions with fragments of data is incorrect, as previous versions will be just junks (in terms of file view), so this doesn't seems to be good option. Commented Aug 21, 2012 at 20:12
  • Yeah if your actually trying to 'render' the complete file it will be junk -- are you trying to add extra pages to a PDF or something?? Commented Aug 21, 2012 at 20:15
  • I'm trying to upload a file using VF page, at end after successful upload user will/might try to view file. Commented Aug 21, 2012 at 20:23

Yes contentversion's versiondata is not updateable. However It maintains a versionhistory object called contentversionhistory.


You can use Salesforce SOAP-based API to upload files into a Salesforce CRM Content. This link provides a sample Java application that uses that API:


You must log in to answer this question.

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