0

I searched lot and found nothing about how to send files. Even in google documentation there is nothing about sending file using Javascript sdk.

See here https://developers.google.com/drive/v3/web/manage-uploads

So right now I'm converting the nodeJs script to javascript. And they used fs to get the readstream. And I have no idea how to do that in javascript. Closet I can get to this...

var file = uploadButton.files[0]
var fileName = uploadButton.files[0].name

var fileMetadata = {
  'name': fileName
};

var media = {
  mimeType: 'image/jpeg',
  body: file
};

gapi.client.drive.files.create({
   resource: fileMetadata,
   media: media.result,
   fields: 'id'
}).execute();

Above code creates the empty file with then fileName and no content inside on it.

  • Is it the same behavior regardless of file type (mimeType)? Have you tried the answers [here](https://stackoverflow.com/q/34905363/4625829)? – AL. May 31 '17 at 11:40

1 Answers1

0

In order to upload a file to your google drive you need to use a google request object and 'POST' the file. You can see an example in this answer. Keep in mind that you need to get your API keys in order to initialise your google drive client object.

Aurovrata
  • 2,000
  • 27
  • 45