简体   繁体   中英

Node js create folder and insert file in google drive

I am looking for creating a folder inside the specified folder and want to insert file to the create one folder. I am using google-drive library and

here they have provided API like

googleDrive(token).files().insert(meta, params, callback)

I have parent folder id , name for sub folder and file in bytearray. so for my situation what should be meta, param for the insert function.

Check the NodeJS implementation for Inserting a file in a folder as according to the docs, a folder is essentially a file.

var folderId = '0BwwA4oUTeiV1TGRPeTVjaWRDY1E';
var fileMetadata = {
  'name': 'photo.jpg',
  parents: [ folderId ]
};
var media = {
  mimeType: 'image/jpeg',
  body: fs.createReadStream('files/photo.jpg')
};
drive.files.create({
   resource: fileMetadata,
   media: media,
   fields: 'id'
}, function(err, file) {
  if(err) {
    // Handle error
    console.log(err);
  } else {
    console.log('File Id: ', file.id);
  }
});

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