Upload Files

Upload documents and images or update the file with a new version.

Salesforce stores files uploaded to a record or group as a ContentDocument. Each file has a ContentVersion record that corresponds to a specific version of the file. Additionally, ContentDocumentLink holds the polymorphic relationships between a file and where it's shared, such as a users, groups, and records. For information about working with files, see ContentDocument in Object Reference for Salesforce and Lightning Platform.

User Interface API provides two ways to upload a file in a request.

To prevent duplication of file uploads, such as in situations where the network connection is unstable, use Idempotency Record Writes.

Note

Upload a New File

This request uploads an image with the .csv file extension. It creates a new ContentDocument, ContentVersion, and ContentDocumentLink in one request. After the file is uploaded, you can view it in Files home.

Example POST Request
POST /ui-api/records/content-documents/content-versions
{
  "description": "My test file",
  "title": "CSV File"
}
Example CURL Request
curl -H "X-PrettyPrint: 1"
-F 'json={"title":"CSV File", "description":"My test file"};type=application/json'
-F 'fileData=@aa.csv;type=application/octet-stream'
-X POST https://{instance-name}.salesforce.com/services/data/v57.0/ui-api/records/content-documents/content-versions
-H 'Authorization: Bearer your_access_token_here'
Example Response
{
  "contentDocument" : {
    "apiName" : "ContentDocument",
    "childRelationships" : { },
    "eTag" : "32e236323d9e6feea5412bb694a9b33d",
    "fields" : {
      "CreatedDate" : {
        "displayValue" : "11/2/2022, 11:13 AM",
        "value" : "2022-11-02T18:13:53.000Z"
      },
      "Description" : {
        "displayValue" : null,
        "value" : "My test file"
      },
      "Id" : {
        "displayValue" : null,
        "value" : "069RM0000008MbJYAU"
      },
      "LastModifiedById" : {
        "displayValue" : null,
        "value" : "005RM000002dpIzYAI"
      },
      "LastModifiedDate" : {
        "displayValue" : "11/2/2022, 11:13 AM",
        "value" : "2022-11-02T18:13:53.000Z"
      },
      "SystemModstamp" : {
        "displayValue" : null,
        "value" : "2022-11-02T18:13:54.000Z"
      },
      "Title" : {
        "displayValue" : null,
        "value" : "CSV File"
      }
    },
    "id" : "069RM0000008MbJYAU",
    "lastModifiedById" : "005RM000002dpIzYAI",
    "lastModifiedDate" : "2022-11-02T18:13:53.000Z",
    "recordTypeId" : null,
    "recordTypeInfo" : null,
    "systemModstamp" : "2022-11-02T18:13:54.000Z",
    "weakEtag" : 1667412834000
  },
  "contentDocumentLinks" : [ {
    "apiName" : "ContentDocumentLink",
    "childRelationships" : { },
    "eTag" : "a9e9ca5f7e2eb85af2aef5ed122350c2",
    "fields" : {
      "ContentDocumentId" : {
        "displayValue" : null,
        "value" : "069RM0000008MbJYAU"
      },
      "Id" : {
        "displayValue" : null,
        "value" : "06ARM00000095a72AA"
      },
      "LinkedEntityId" : {
        "displayValue" : null,
        "value" : "005RM000002dpIzYAI"
      },
      "ShareType" : {
        "displayValue" : "Inferred",
        "value" : "I"
      },
      "SystemModstamp" : {
        "displayValue" : null,
        "value" : "2022-11-02T18:13:54.000Z"
      }
    },
    "id" : "06ARM00000095a72AA",
    "lastModifiedById" : null,
    "lastModifiedDate" : null,
    "recordTypeId" : null,
    "recordTypeInfo" : null,
    "systemModstamp" : "2022-11-02T18:13:54.000Z",
    "weakEtag" : 1667412834000
  } ],
  "contentVersion" : {
    "apiName" : "ContentVersion",
    "childRelationships" : { },
    "eTag" : "0cbf5c6af463dbda0d0741eeda132d7a",
    "fields" : {
      "ContentSize" : {
        "displayValue" : null,
        "value" : "26224"
      },
      "CreatedDate" : {
        "displayValue" : "11/2/2022, 11:13 AM",
        "value" : "2022-11-02T18:13:53.000Z"
      },
      "Description" : {
        "displayValue" : null,
        "value" : "My test file"
      },
      "Id" : {
        "displayValue" : null,
        "value" : "068RM0000008SBhYAM"
      },
      "LastModifiedById" : {
        "displayValue" : null,
        "value" : "005RM000002dpIzYAI"
      },
      "LastModifiedDate" : {
        "displayValue" : "11/2/2022, 11:13 AM",
        "value" : "2022-11-02T18:13:53.000Z"
      },
      "SystemModstamp" : {
        "displayValue" : null,
        "value" : "2022-11-02T18:13:54.000Z"
      },
      "Title" : {
        "displayValue" : null,
        "value" : "CSV File"
      },
      "VersionDataUrl" : {
        "displayValue" : null,
        "value" : "https://{instance-name}.documentforce.com/sfc/servlet.shepherd/version/download/068RM0000008SBh"
      }
    },
    "id" : "068RM0000008SBhYAM",
    "lastModifiedById" : "005RM000002dpIzYAI",
    "lastModifiedDate" : "2022-11-02T18:13:53.000Z",
    "recordTypeId" : "012000000000000AAA",
    "recordTypeInfo" : null,
    "systemModstamp" : "2022-11-02T18:13:54.000Z",
    "weakEtag" : 1667412834000
  }

Upload a File Version

This request uploads a new version of an image file with a new file name. It creates a new ContentVersion, and updates the existing objects to reference the new ContentVersion.

Example POST Request
POST /ui-api/records/content-documents/069RM0000008MbEYAU/content-versions
{
  "title": "Updated product image"
}
Example CURL Request
curl -H "X-PrettyPrint: 1" 
-F 'json={"title":"Updated product image"};type=application/json' 
-F 'fileData=@Test.PNG;type=application/octet-stream' 
-X POST 'https://{instance-name}.salesforce.com/services/data/v57.0/ui-api/records/content-documents/069RM0000008MbEYAU/content-versions' 
-H 'Authorization: Bearer your_access_token_here'
Example Response
{
  "contentDocument" : {
    "apiName" : "ContentDocument",
    "childRelationships" : { },
    "eTag" : "8a5ed89e115ff7f99e4d00e6ec07c0f3",
    "fields" : {
      "CreatedDate" : {
        "displayValue" : "11/2/2022, 10:19 AM",
        "value" : "2022-11-02T17:19:28.000Z"
      },
      "Description" : {
        "displayValue" : null,
        "value" : null
      },
      "Id" : {
        "displayValue" : null,
        "value" : "069RM0000008MbEYAU"
      },
      "LastModifiedById" : {
        "displayValue" : null,
        "value" : "005RM000002dpIzYAI"
      },
      "LastModifiedDate" : {
        "displayValue" : "11/2/2022, 10:53 AM",
        "value" : "2022-11-02T17:53:59.000Z"
      },
      "SystemModstamp" : {
        "displayValue" : null,
        "value" : "2022-11-02T17:54:00.000Z"
      },
      "Title" : {
        "displayValue" : null,
        "value" : "Updated product image"
      }
    },
    "id" : "069RM0000008MbEYAU",
    "lastModifiedById" : "005RM000002dpIzYAI",
    "lastModifiedDate" : "2022-11-02T17:53:59.000Z",
    "recordTypeId" : null,
    "recordTypeInfo" : null,
    "systemModstamp" : "2022-11-02T17:54:00.000Z",
    "weakEtag" : 1667411640000
  },
  "contentDocumentLinks" : [ {
    "apiName" : "ContentDocumentLink",
    "childRelationships" : { },
    "eTag" : "0e32a473e9bd0bb69eb23fb1c0d8115c",
    "fields" : {
      "ContentDocumentId" : {
        "displayValue" : null,
        "value" : "069RM0000008MbEYAU"
      },
      "Id" : {
        "displayValue" : null,
        "value" : "06ARM00000095a32AA"
      },
      "LinkedEntityId" : {
        "displayValue" : null,
        "value" : "001RM000005XNLIYA4"
      },
      "ShareType" : {
        "displayValue" : "Inferred",
        "value" : "I"
      },
      "SystemModstamp" : {
        "displayValue" : null,
        "value" : "2022-11-02T17:19:31.000Z"
      }
    },
    "id" : "06ARM00000095a32AA",
    "lastModifiedById" : null,
    "lastModifiedDate" : null,
    "recordTypeId" : null,
    "recordTypeInfo" : null,
    "systemModstamp" : "2022-11-02T17:19:31.000Z",
    "weakEtag" : 1667409571000
  }, {
    "apiName" : "ContentDocumentLink",
    "childRelationships" : { },
    "eTag" : "ccfa6db5bfad0c23d0aa613b69fbaec5",
    "fields" : {
      "ContentDocumentId" : {
        "displayValue" : null,
        "value" : "069RM0000008MbEYAU"
      },
      "Id" : {
        "displayValue" : null,
        "value" : "06ARM00000095a22AA"
      },
      "LinkedEntityId" : {
        "displayValue" : null,
        "value" : "005RM000002dpIzYAI"
      },
      "ShareType" : {
        "displayValue" : "Inferred",
        "value" : "I"
      },
      "SystemModstamp" : {
        "displayValue" : null,
        "value" : "2022-11-02T17:19:32.000Z"
      }
    },
    "id" : "06ARM00000095a22AA",
    "lastModifiedById" : null,
    "lastModifiedDate" : null,
    "recordTypeId" : null,
    "recordTypeInfo" : null,
    "systemModstamp" : "2022-11-02T17:19:32.000Z",
    "weakEtag" : 1667409572000
  } ],
  "contentVersion" : {
    "apiName" : "ContentVersion",
    "childRelationships" : { },
    "eTag" : "7b64a64ff99e3141f6fdbf7a5278d424",
    "fields" : {
      "ContentSize" : {
        "displayValue" : null,
        "value" : "324337"
      },
      "CreatedDate" : {
        "displayValue" : "11/2/2022, 10:53 AM",
        "value" : "2022-11-02T17:53:59.000Z"
      },
      "Description" : {
        "displayValue" : null,
        "value" : null
      },
      "Id" : {
        "displayValue" : null,
        "value" : "068RM000000228mYAA"
      },
      "LastModifiedById" : {
        "displayValue" : null,
        "value" : "005RM000002dpIzYAI"
      },
      "LastModifiedDate" : {
        "displayValue" : "11/2/2022, 10:53 AM",
        "value" : "2022-11-02T17:53:59.000Z"
      },
      "SystemModstamp" : {
        "displayValue" : null,
        "value" : "2022-11-02T17:54:01.000Z"
      },
      "Title" : {
        "displayValue" : null,
        "value" : "Updated product image"
      },
      "VersionDataUrl" : {
        "displayValue" : null,
        "value" : "https://{instance-name}.documentforce.com/sfc/servlet.shepherd/version/download/068RM000000228m"
      }
    },
    "id" : "068RM000000228mYAA",
    "lastModifiedById" : "005RM000002dpIzYAI",
    "lastModifiedDate" : "2022-11-02T17:53:59.000Z",
    "recordTypeId" : "012000000000000AAA",
    "recordTypeInfo" : null,
    "systemModstamp" : "2022-11-02T17:54:01.000Z",
    "weakEtag" : 1667411641000
  }
}