Newer Version Available

This content describes an older version of this product. View Latest

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.

Upload a New File

This request uploads an image with the .jpeg file extension. It creates a new ContentDocument, ContentVersion, and ContentDocumentLink in one request.

Example POST Request
1POST /ui-api/records/content-documents/content-versions
1{
2  "description": "A description of the product",
3  "title": "Product Image"
4}
Example CURL Request
1curl -H "X-PrettyPrint: 1" -F
2'json={"title":"Product Image", "description":"A description of the product"};type=application/json' -F
3"fileData=@your_file_name.jpeg;type=application/octet-stream" -X
4POST https://{instance-name}.salesforce.com/services/data/v56.0/ui-api/records/content-documents/content-versions -H
5"Authorization: Bearer your_token_here"
Example Response
1{
2  "contentDocument" : {
3    "archivedById" : null,
4    "archivedDate" : null,
5    "checksum" : "1355037122bdd1659a1ccdaca8ce3205",
6    "contentAssetId" : null,
7    "contentModifiedDate" : "2022-07-12T20:52:11.000Z",
8    "contentSize" : 36397,
9    "createdById" : "005xx000001X7fN",
10    "createdDate" : "2022-07-12T20:52:11.000Z",
11    "description" : "A description of the product",
12    "displayValue" : null,
13    "division" : "1",
14    "eTag" : "f2056bae93b0b3b9c54a0c552648bd42",
15    "fileType" : "JPG",
16    "id" : "069xx0000004FBkAAM",
17    "isArchived" : false,
18    "lastModifiedById" : "005xx000001X7fN",
19    "lastModifiedDate" : "2022-07-12T20:52:11.000Z",
20    "lastReferenceDate" : null,
21    "lastViewedDate" : null,
22    "latestPublishedVersionId" : "068xx0000004FZw",
23    "ownerId" : "005xx000001X7fN",
24    "parentId" : null,
25    "publishStatus" : "R",
26    "recordTypeId" : null,
27    "sharingOption" : "A",
28    "systemModstamp" : "2022-07-12T20:52:11.000Z",
29    "title" : "LCS LIV",
30    "weakEtag" : 1657659131000
31  },
32  "contentDocumentLinks" : [ {
33    "contentDocumentId" : "069xx0000004FBk",
34    "id" : "06Axx0000004FDMEA2",
35    "linkedEntityId" : "005xx000001X7fNAAS",
36    "shareType" : "INFERRED",
37    "systemModstamp" : null,
38    "visibility" : null,
39    "weakEtag" : 0
40  } ],
41  "contentVersion" : {
42    "checksum" : "1355037122bdd1659a1ccdaca8ce3205",
43    "contentBodyId" : "05Txx0000004FZw",
44    "contentLocation" : "S",
45    "contentModifiedBy" : "005xx000001X7fN",
46    "contentModifiedDate" : "2022-07-12T20:52:11.000Z",
47    "contentSize" : 36397,
48    "contentUrl" : null,
49    "createdById" : "005xx000001X7fN",
50    "createdDate" : "2022-07-12T20:52:11.000Z",
51    "description" : "A description of the product",
52    "eTag" : "833e852b7780e2f30b0e05f40b2ba1ec",
53    "externalDataSourceId" : null,
54    "externalDocumentInfo1" : null,
55    "externalDocumentInfo2" : null,
56    "featuredContentBoost" : null,
57    "featuredContentDate" : null,
58    "fileExtension" : null,
59    "fileType" : "JPG",
60    "firstPublishLocationId" : null,
61    "id" : "068xx0000004FZwAAM",
62    "isAssetEnabled" : false,
63    "isEncrypted" : false,
64    "isLatest" : true,
65    "isMajorVersion" : false,
66    "language" : "1",
67    "lastModifiedById" : "005xx000001X7fN",
68    "lastModifiedDate" : "2022-07-12T20:52:11.000Z",
69    "negativeRatingCount" : 0,
70    "networkId" : null,
71    "origin" : "H",
72    "ownerId" : null,
73    "pathOnClient" : "working_at_home.jpg",
74    "positiveRatingCount" : 0,
75    "publishStatus" : "R",
76    "ratingCount" : 0,
77    "reasonForChange" : null,
78    "recordTypeId" : null,
79    "sharingOption" : "A",
80    "sharingPrivacy" : "N",
81    "systemModstamp" : null,
82    "tagCsv" : null,
83    "textPreview" : null,
84    "title" : "Product Image",
85    "versionNumber" : "1",
86    "weakEtag" : 1657659131000
87  }
88}

Upload a File Version

This request uploads a version of the image discussed in the previous example. It creates a new ContentVersion, and updates the existing objects to reference the new ContentVersion.

Example POST Request
1POST /ui-api/records/content-documents/0692L00000BDVevQAH/content-versions
1{
2  "title": "Product Image"
3}
Example CURL Request
1curl -H "X-PrettyPrint: 1" -F
2'json={"title":"Updated product image"};type=application/json' -X
3POST https://{instance_name}.salesforce.com/services/data/v56.0/ui-api/records/content-documents/0692L00000BDVevQAH/content-versions -H
4"Authorization: Bearer your_token_here"
Example Response
1{
2  "contentDocument" : {
3    "archivedById" : null,
4    "archivedDate" : null,
5    "checksum" : "1355037122bdd1659a1ccdaca8ce3205",
6    "contentAssetId" : null,
7    "contentModifiedDate" : "2022-07-12T20:52:11.000Z",
8    "contentSize" : 36397,
9    "createdById" : "005xx000001X7fN",
10    "createdDate" : "2022-07-12T20:52:11.000Z",
11    "description" : "Another Test",
12    "displayValue" : null,
13    "division" : "1",
14    "eTag" : "f2056bae93b0b3b9c54a0c552648bd42",
15    "fileType" : "JPG",
16    "id" : "069xx0000004FBkAAM",
17    "isArchived" : false,
18    "lastModifiedById" : "005xx000001X7fN",
19    "lastModifiedDate" : "2022-07-12T20:52:11.000Z",
20    "lastReferenceDate" : null,
21    "lastViewedDate" : null,
22    "latestPublishedVersionId" : "068xx0000004FZw",
23    "ownerId" : "005xx000001X7fN",
24    "parentId" : null,
25    "publishStatus" : "R",
26    "recordTypeId" : null,
27    "sharingOption" : "A",
28    "systemModstamp" : "2022-07-12T20:52:11.000Z",
29    "title" : "Updated product image",
30    "weakEtag" : 1657659131000
31  },
32  "contentDocumentLinks" : [ {
33    "contentDocumentId" : "069xx0000004FBk",
34    "id" : "06Axx0000004FDMEA2",
35    "linkedEntityId" : "005xx000001X7fNAAS",
36    "shareType" : "INFERRED",
37    "systemModstamp" : null,
38    "visibility" : null,
39    "weakEtag" : 0
40  } ],
41  "contentVersion" : {
42    "checksum" : "1355037122bdd1659a1ccdaca8ce3205",
43    "contentBodyId" : "05Txx0000004FZw",
44    "contentLocation" : "S",
45    "contentModifiedBy" : "005xx000001X7fN",
46    "contentModifiedDate" : "2022-07-12T20:52:11.000Z",
47    "contentSize" : 36397,
48    "contentUrl" : null,
49    "createdById" : "005xx000001X7fN",
50    "createdDate" : "2022-07-12T20:52:11.000Z",
51    "description" : "A description of the product",
52    "eTag" : "833e852b7780e2f30b0e05f40b2ba1ec",
53    "externalDataSourceId" : null,
54    "externalDocumentInfo1" : null,
55    "externalDocumentInfo2" : null,
56    "featuredContentBoost" : null,
57    "featuredContentDate" : null,
58    "fileExtension" : null,
59    "fileType" : "JPG",
60    "firstPublishLocationId" : null,
61    "id" : "068xx0000004FZwAAM",
62    "isAssetEnabled" : false,
63    "isEncrypted" : false,
64    "isLatest" : true,
65    "isMajorVersion" : false,
66    "language" : "1",
67    "lastModifiedById" : "005xx000001X7fN",
68    "lastModifiedDate" : "2022-07-12T20:52:11.000Z",
69    "negativeRatingCount" : 0,
70    "networkId" : null,
71    "origin" : "H",
72    "ownerId" : null,
73    "pathOnClient" : "working_at_home.jpg",
74    "positiveRatingCount" : 0,
75    "publishStatus" : "R",
76    "ratingCount" : 0,
77    "reasonForChange" : null,
78    "recordTypeId" : null,
79    "sharingOption" : "A",
80    "sharingPrivacy" : "N",
81    "systemModstamp" : null,
82    "tagCsv" : null,
83    "textPreview" : null,
84    "title" : "Updated product image",
85    "versionNumber" : "2",
86    "weakEtag" : 1657659131000
87  }
88}