Newer Version Available
コンテンツを含むリポジトリファイルの更新
この例では、updateRepositoryFile(repositoryId, repositoryFileId, file, fileData) をコールして、リポジトリ内のファイルのコンテンツとメタデータを更新します。ファイルを更新した後、ファイルの ID、名前、説明、外部 URL、およびダウンロード 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//Metadata: description field
14final ConnectApi.ContentHubFieldValueInput fieldValueInputNameDesc = new ConnectApi.ContentHubFieldValueInput();
15fieldValueInputNameDesc.name = 'description';
16fieldValueInputNameDesc.value = 'that updates the former description';
17updatedItem.fields.add(fieldValueInputNameDesc);
18
19//Binary content
20final Blob updatedFileBlob = Blob.valueOf('even more awesome content for updated file');
21final String updatedFileMimeType = 'text/plain';
22final ConnectApi.BinaryInput fileBinaryInput = new ConnectApi.BinaryInput(updatedFileBlob, updatedFileMimeType, updatedFileName);
23
24final ConnectApi.RepositoryFileDetail updatedFile = ConnectApi.ContentHub.updateRepositoryFile(gDriveRepositoryId, gDriveFileId, updatedItem);
25System.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}));