简体   繁体   English

如何使用 API 从谷歌驱动器下载文件作为 Blob

[英]How to download a file as Blob from google drive using API

I have been working on a code that will download a blob from the google drive using their API(V3).我一直在研究一个代码,它将使用他们的 API(V3)从谷歌驱动器下载一个 blob。 I want to get this working as I need to duplicate the file from google drive to firebase storage by using the fileUrl/ fileID.我想让这个工作,因为我需要使用 fileUrl/fileID 将文件从谷歌驱动器复制到 firebase 存储。

I am able to export the pdf file after following a blog on medium在关注medium上的博客后,我能够导出 pdf 文件

To do this you need to:为此,您需要:

  1. Get Drive file blob You can get the webContentLink and open it to download the file. 获取 Drive 文件 blob您可以获取webContentLink并打开它以下载文件。 If you were to curl it you would get the file contents.如果您要使用 curl,您将获得文件内容。
  2. Create a reference to the file 创建对文件的引用
// Create a root reference
var storageRef = firebase.storage().ref();

// Create a reference to 'mountains.jpg'
var mountainsRef = storageRef.child('mountains.jpg');
  1. Upload the Blob to the reference 将 Blob 上传到参考
 var file = ... // use the Blob you got on step 1
 ref.put(file).then(function(snapshot) {
   console.log('Uploaded a blob or file!');
 });

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM