google-drive-api - 是否可以使用 Google Drive API 从共享的 .zip 文件中获取文件
问题描述
假设以下 .zip 文件:
unzip -l myarchive.zip
Archive: myarchive.zip
Length Date Time Name
--------- ---------- ----- ----
3663 1980-00-00 00:00 sub_dir1/file1.txt
4573 1980-00-00 00:00 sub_dir1/file2.txt
6021 1980-00-00 00:00 sub_dir2/file1.txt
6627 1980-00-00 00:00 file1.txt
以下命令在文件系统中时从 .zip 文件中提取文件 sub_dir1/file1.txt。
unzip -p myarchive.zip sub_dir1/file1.txt > file1.txt
但如果 .zip 文件在 Google Drive 中并带有共享链接(例如 fileId 为:1234567...v4rzj),
是否可以进行 Google Drive API 查询以从 .zip 文件中获取特定文件(例如 sub_dir1/file1.txt)?
解决方案
谷歌驱动器只是一个文件存储系统,它本身并不能以这种方式解压缩文件或检查文件的内容。google drive api 让您能够创建、更新、删除上传和下载文件。
其他选项。
因为您的 unzip 命令适用于本地存储在您机器上的文件。您需要先从 Google 驱动器下载文件,然后运行解压缩。
由于您没有提到您打算使用哪种编程语言,我建议您查看文档以获取示例。
这是一个使用 Java 的示例,您还需要授权码。
String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);
推荐阅读
- docker - 使用 SSL 通信节点导出器目标
- javascript - Javascript迭代计数另一个数组中的数组实例
- javascript - 当用户单击确切的位置时,如何创建粒子?
- python - 解决 SSL 问题:WRONG_VERSION_NUMBER
- python - 是否有 Python/Numpy/其他函数用于计算 X、Y 和 Z 平面中沿指定方位角的两条线之间的距离?
- c# - 带量词的正则表达式负向后追溯
- python - SQLITE3 SELECT 语句不返回数据
- android - 在 Android 上设置全局代理 PAC
- docker - 使用 Mocha 和 Node 在 Docker 中进行 VSCode 调试
- websocket - 使用 Apache Camel AHC-WS Websocket 组件进行 JWT 不记名令牌身份验证