如何使用Google Drive API上传文件?

莱吉尔

我正在尝试使用Android上的Google云端硬盘api上传文件

https://github.com/googlesamples/google-services/tree/master/android/signin/app/src/main/java/com/google/samples/quickstart/signin

我在上面的链接中注册了SignInActivityWithDrive.java。

但是没有上传文件,下载文件的示例

我想知道如何上传和下载文件

谢谢

雅克

您可以在文档中找到上下载的基本示例

上载中

您可以通过以下任意一种方式发送上传请求:

  • 简单上传:uploadType=media用于快速传输小文件(5 MB或更小)。要执行简单上传,请参阅执行简单上传
  • 分段上传:uploadType=multipart快速传输小文件(5 MB或更少)和描述文件的元数据,所有操作均在单个请求中完成。要执行分段上传,请参阅执行分段上传
  • 断点续传:uploadType=resumable对于更可靠的传输,尤其是大文件传输。对于大多数应用程序而言,可恢复的上载是一个不错的选择,因为它们也适用于小型文件,但每次上载都会产生一个额外的HTTP请求。要执行可恢复上传,请参考执行可恢复上传

以下示例显示了如何使用客户端库上传图像:

File fileMetadata = new File();
fileMetadata.setName("photo.jpg");
java.io.File filePath = new java.io.File("files/photo.jpg");
FileContent mediaContent = new FileContent("image/jpeg", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
    .setFields("id")
    .execute();
System.out.println("File ID: " + file.getId());

正在下载

根据您要执行的下载类型(文件,Google文档或内容链接),您将使用以下URL之一:

基本下载的示例是:

String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
    .executeMediaAndDownloadTo(outputStream);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Google Drive API权限不足,无法上传文件

使用Google Drive API上传文件夹中的文件

Google Drive PHP API-简单文件上传

Google Drive Python API;上传不是文件的媒体对象

Google Drive API-上传和导出文件

使用Google Drive Api上传图像文件

是否可以从Google Drive API获取上传文件的链接

Drive Api V3-如何命名要上传的文件?

Google Drive API和从浏览器上传的文件

无法使用Python Drive API上传> 200 MB的csv文件

Google Drive API从字符串上传文件

Google Drive API分段上传导致文件损坏

如何使用PHP Google Drive API在Google Drive上上传文件

使用Google Drive API与特定用户共享上传的文件

如何使用Google Drive API和Python将文件上传到特定文件夹?

如何使用uploadType = resumable将文件上传到Google Drive API

如何使用Google Drive API将文件上传到Google Drive?

使用Google Drive API上传PDF文件-Google Drive Web Client中没有预览

Google Drive PHP API空上传的文件

使用Google Drive API在指定的Google Drive中上传文件

在Azure上,Google Drive Api文件上传失败,返回null

使用 Google Drive API 时不显示上传的文件

使用 Drive API 和 PHP 将文件上传到 Teamdrives

如何使用 Google Drive API V3 将文件上传到 Group Drive(共享驱动器)?

文件上传到 Google Drive

如何使用 Google Drive API 上传我的 Drive (PHP) 中的文件?

如何使用python请求使用google drive API上传和删除文件

如何从 Google Drive 上传和下载文件(使用 Rest Api v3)

如何使用python google drive api将文件夹上传到共享的google drive?