upload success with return id. and tried to drive.files.list that too. it exists. but file not exist in drive? what is this? I try to upload in specific folder by id. wheres file upload location?
const { google } = require('googleapis');
const fs = require('fs');
const credentials = require('./credentials.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 });
(async () => {
const fileMetadata = {
name: 'naruto.jpg'
};
const media = {
mimeType: 'image/jpeg',
body: fs.createReadStream('naruto.jpg')
};
const res = await drive.files.create({
q: `'1PhND1fjEDnL63BbrLmw2V4M4B6jIfP8Q' in parents`,
resource: fileMetadata,
media: media,
fields: 'id'
});
console.log(res.data);
})();
You appear to be using a service account. A service account has its own google drive account and in your case you appear to have uploaded the file to the Service accounts google drive account.
If you want to upload the file to your own personal google drive account you should share a directory with the service account on your personal drive account and then when you create the file metadata make sure to set the parent directory where you would like the file uploaded to .
let fileMetadata = {
'name': 'icon.png',
'parents': [ '10krlloIS2i_2u_ewkdv3_1NqcpmWSL1w' ]
};
Code ripped from Upload Image to Google drive with Node Js also Google drive API upload file with Nodejs + service account