Newer Version Available

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

Update a Repository File with Content

This example calls updateRepositoryFile(repositoryId, repositoryFileId, file, fileData) to update the content and metadata of a file in a repository. After the file is updated, we show the file’s ID, name, description, external URL, and download URL.
1final String gDriveRepositoryId = '0XCxx00000000ODGAY', gDriveFolderId = 'folder:0B0lTys1KmM3sSVJ2bjIzTGFqSWs', gDriveFileId = 'document:1q9OatVpcyYBK-JWzp_PhR75ulQghwFP15zhkamKrRcQ';
2
3final ConnectApi.ContentHubItemInput updatedItem = new ConnectApi.ContentHubItemInput();
4updatedItem.itemTypeId = 'document'; //see getAllowedTypes for any file item types available for creation/update
5updatedItem.fields = new List<ConnectApi.ContentHubFieldValueInput>();
6
7//Metadata: name field
8final ConnectApi.ContentHubFieldValueInput fieldValueInputName = new ConnectApi.ContentHubFieldValueInput();
9fieldValueInputName.name = 'name';
10fieldValueInputName.value =  'updated file name.txt';
11updatedItem.fields.add(fieldValueInputName);
12
13//Binary content
14final Blob updatedFileBlob = Blob.valueOf('even more awesome content for updated file');
15final String updatedFileMimeType = 'text/plain';
16final ConnectApi.BinaryInput fileBinaryInput = new ConnectApi.BinaryInput(updatedFileBlob, updatedFileMimeType, updatedFileName);
17
18final ConnectApi.RepositoryFileDetail updatedFile = ConnectApi.ContentHub.updateRepositoryFile(gDriveRepositoryId, gDriveFileId, updatedItem);
19System.debug(String.format('Updated file - id: \'\'{0}\'\', name: \'\'{1}\'\', description: \'\'{2}\'\',\n external URL: \'\'{3}\'\', download URL: \'\'{4}\'\'',  new String[]{ updatedFile.id, updatedFile.name, updatedFile.description, updatedFile.externalDocumentUrl, updatedFile.downloadUrl}));