如何使用newRevision参数在谷歌驱动器API时上传文件



我从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();

相关内容

  • 没有找到相关文章

最新更新