2

i want to upload files to google drive using nodeJS as backend. I have used google drive API v3. I get the file id and type in response after uploading a file.

drive.files.create({
    resource: {
            name: 'Test',
            mimeType: 'image/jpeg'
        },
    media: {
            mimeType: 'image/jpeg',
            body: fileData
        }
    }, function(err, result){
        if(err)
            res.send(err);
        else
            res.send(result);
    });

but what i want is when i upload a file i want it as publicly accessible. i want the shareable link of that file in response. Is there any way to do so ? i have implemented the way given here : https://developers.google.com/drive/v3/web/manage-sharing which works fine with s.showSettingsDialog(). But i want the shareable link at the time i upload the file.

Ketan Saresa
  • 109
  • 1
  • 6
  • got the answer. you can use the id which you get after uploading the file and then get the metadata info of that file using file id. there will be a webviewlink parameter which you need to include in the field parameter which is optional. you will get the webviewlink of that file in response. – Ketan Saresa Jul 15 '16 at 14:16

1 Answers1

0

You could simply save this url < https://drive.google.com/open?id=FILE_ID > in your database and replace the FILE_ID with the actual file id stored in your google drive which in your case would be result.id

Marshall
  • 11
  • 5
  • How to get a shareable link? not a link through which only the owner of the file can access? – Abhishek Mar 02 '20 at 17:05
  • @Abhishek https://stackoverflow.com/a/54893611/8802812 This can help you. So basically, you ll have to set the permission as public and then the link will be accessible for everybody – Omkar Kulkarni May 14 '20 at 11:03