我从https://developers.google.com/drive/v2/reference/files/update获得以下Java代码
import com.google.api.client.http.FileContent;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import java.io.IOException;
// ...
public class MyClass {
// ...
/**
* Update an existing file's metadata and content.
*
* @param service Drive API service instance.
* @param fileId ID of the file to update.
* @param newTitle New title for the file.
* @param newDescription New description for the file.
* @param newMimeType New MIME type for the file.
* @param newFilename Filename of the new content to upload.
* @param newRevision Whether or not to create a new revision for this
* file.
* @return Updated file metadata if successful, {@code null} otherwise.
*/
private static File updateFile(Drive service, String fileId, String newTitle,
String newDescription, String newMimeType, String newFilename, boolean newRevision) {
try {
// First retrieve the file from the API.
File file = service.files().get(fileId).execute();
// File's new metadata.
file.setTitle(newTitle);
file.setDescription(newDescription);
file.setMimeType(newMimeType);
// File's new content.
java.io.File fileContent = new java.io.File(newFilename);
FileContent mediaContent = new FileContent(newMimeType, fileContent);
// Send the request to the API.
File updatedFile = service.files().update(fileId, file, mediaContent).execute();
return updatedFile;
} catch (IOException e) {
System.out.println("An error occurred: " + e);
return null;
}
}
// ...
}
我想将
newRevision
设置为false。但是,该代码示例未显示我们如何应用它?知道如何应用
newRevision
吗? 最佳答案
c#的Drive.Files.Update解决方案。
要设置newRevision,您应该首先获取请求,设置标志,然后执行。
Drive.Files.Update request = service.files().update(fileId, file, mediaContent);
// set newRevision
request.setNewRevision(newRevision);
// execute
File updatedFile = request.execute();