简体   繁体   中英

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). I want to get this working as I need to duplicate the file from google drive to firebase storage by using the fileUrl/ fileID.

I am able to export the pdf file after following a blog on medium

To do this you need to:

  1. Get Drive file blob You can get the webContentLink and open it to download the file. If you were to curl it you would get the file contents.
  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
 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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