0

I want to pick files from google drive as a file object. I am working in vuejs and hence used the vue-google-picker. Google picker is actually returning URL, that I am converting to a file. My code to convert to file:

   async convertToFile(docs) { 
        return new Promise(
            resolve => {
                docs.map(doc => { 
                    if (doc.url) {
                        gapi.load('client',  function () {
                            gapi.client.load('drive', 'v3', function () {
                                var file =  gapi.client.drive.files.get({ 'fileId': doc.id, 'alt': 'media' });                            
                                console.log(file)
                                file.execute(function (resp) {
                                    console.log(resp)                                          
                                    resolve(resp)
                                });
                            });
                        });
                    }    
                });  
            }
        )         
    }   

console.log(file) shows object like this: picture

While console.log(resp) shows false. If I see the network tab, then I am receiving the base64 object of the file in preview tab.

How to receive that base64 object in code? What is a method of it? I am also open to any alternative method to receive object file from google drive.

Maha Waqar
  • 585
  • 1
  • 10
  • 24

1 Answers1

0

You need to await for drive.files.get method

const file =  await gapi.client.drive.files.get({ 'fileId': doc.id, 'alt': 'media' });
console.log(file.body) // here will be the data