0

I'm trying to upload different files and folders to my Google Drive. For each upload I get a success response in the callback (code 200), meaning they were uploaded. When I request for a list of files, I also see the files I've uploaded. But when I open the drive, I can't see them there. Am I looking in the wrong place?

const {google} = require ('googleapis');
var fs = require('fs');
const credentials = require('./my-project-xxxx-1-xxxxxxxxx.json');
const scopes = ['https://www.googleapis.com/auth/drive'];
const auth = new google.auth.JWT(credentials.client_email,
                                 null,
                                 credentials.private_key,
                                 scopes);

const drive = google.drive({'version': 'v3', auth});

var metaData = {'name': 'image.jpg'};

const media = {'mimeType': 'image/jpeg',
               'body': fs.createReadStream('./view_image.jpg')};

drive.files.create({'resource': metaData,
                 'media': media,
                 errorHandling});


function errorHandling (err, file)
{
    if (err)
    {
      console.log(err);
    }
    else
    {
      console.log('SUCCESS ', file);
    }
}
Alex Nelson
  • 1,182
  • 9
  • 19
Kippi
  • 1
  • 2
  • Please edit your question and include your code. Also if your using a service account they were uploaded to its account not yours. – Linda Lawton - DaImTo Apr 14 '20 at 13:15
  • Yes, I'm using service account, this concept is new to me. When I created a service account, did I actually create another user, with it own email and drive? How can I upload to the gmail account user drive, for which I created the user account? Thanks! – Kippi Apr 14 '20 at 14:59
  • 1
    @DalmTo, I found a thread with the same problem. I tried to do like you suggested, shared a folder in my drive with the the service account email, and tried to upload there (I still don't see it). Question is how does google drive api knows to direct the upload to the gmail account drive and not to the service account drive? I'm probably missing something when calling the API, can you please show an example of uploading to a shared folder? Thanks again! https://stackoverflow.com/questions/49663359/how-to-upload-file-to-google-drive-with-service-account-credential – Kippi Apr 14 '20 at 17:00
  • Ok, I missed the rest of the correspondence there - so the solution is to include the shared folder id in the metadata under 'parents' field. That sort it out. I guess this thread can be marked as duplicate. Thanks @DaImTo – Kippi Apr 14 '20 at 17:34

0 Answers0