Reputation: 2320
I'm trying to create a web app with an image upload feature which will upload an image to a user's google drive & returns absolute path of the uploaded image by making use of google drive picker
my Generate Picker function
var picker=new google.picker.PickerBuilder()
.addView(new google.picker.DocsUploadView())
.addView(new google.picker.DocsView())
.setOAuthToken(oauthToken)
.setDeveloperKey("[MY_API]")
.setCallback(imageReceived)
.build();
picker.setVisible(true);
callback function
function imageReceived(data)
{
if (data.action == google.picker.Action.PICKED) {
console.log(data.docs[0].url);
}
I'm able to generate the picker and the file upload also works
however in my upload callback function url is returned in this form
https://docs.google.com/file/d/[something]/edit?usp=drive_web
this url can't be used in an img tag as it is not the absolute path of the image uploaded So how should I get the absolute path ?
Upvotes: 2
Views: 1347
Reputation: 1989
Looking at the documentation (https://developers.google.com/picker/docs/results), it states that you should use "embed_URL" instead.
You can easily debug and check the response. I integrated google picker in one of my projects, I was able to get full url to the image.
Edit: I've checked my code, and I actually had to use google file api to get the link. That is to make an ajax call to https://www.googleapis.com/drive/v2/files/{id} passing file id. Absolute url that you can use in img tag is in 'webContentLink' property.
Note that you have to forward access token in request header when making that ajax call:
var token = gapi.auth.getToken();
$.ajax({....,
beforeSend: function(n) {
n.setRequestHeader("Authorization", "Bearer " + token.access_token)
}}),...
});
Upvotes: 1