dedles
dedles

Reputation: 677

Create and upload a Google Sheet into a particular Folder on Google Drive

I'm using the gapi.client.sheets.spreadsheets.create() method and passing in an object to create a spreadsheet with some predefined values (see: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets).

I would like to use the google picker (https://developers.google.com/picker/docs/) and allow the user to select a folder on their google drive where the created spreadsheet will be insert. Thus far, I haven't been able to figure out how to do this. I've gotten as far as getting both services working individually but don't have any idea how to get them to work together. Should the picker pass a document folder id to the spreadsheet create method? Or should the spreadsheet get created first?

Any advice would be greatly appreciated.

Upvotes: 0

Views: 1187

Answers (1)

ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17623

You dont use Google Picker to assign the created spreadsheet to a folder. Google Picker serves as interface to open, upload to or download files from Drive API. Instead, follow the Inserting a file in a folder guide from the Drive API. Here's a snippet that uses NodeJS which is Javascript:

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);
  }
});

Or, you can try to use addFile using Apps Script.

Upvotes: 0

Related Questions