Skip to content
Advertisement

What’s the correct way to make the uploaded image file accessible via URL – google drive api v3

I have created a project on Google API’s developer console and enabled Google Drive API.

As well as I have created and downloaded Service account credentials .json file which I am using on Node.js backend server and connecting and uploading image files on google drive.

JavaScript
JavaScript


When I upload the file I get the unique file ID in the response.

On the android application as well as on the front end react application I want to display this image file using URL.

enter image description here


I tried https://drive.google.com/open?id=PASTE YOUR ID HERE as well as http://drive.google.com/uc?export=view&id=PASTE YOUR ID HERE but it says you need access.

enter image description here

I also tried publishAuto:true while uploading image but it didn’t work.

What’s the correct way to make the uploaded image file accessible via URL?

Advertisement

Answer

I solved it by creating a new folder and setting the permission for this folder as

JavaScript

and then uploading images to this folder. When I want to display uploaded images I can display using below URL:

JavaScript

Here is the complete code.

JavaScript

Run this code only once.

JavaScript

And then upload as many images as you want in that folder using below code.

JavaScript
Advertisement