Add Images to Products


Add Images to Products



I have a products model and I want to include an image for each product which will be used to display image of a product in product details page. I want my users to be able to select image with a drive picker from our domain's team drive folder. There is an ImageURL field in my products model.



"features" property of my Team Drive is set to: SUPPORT_TEAM_DRIVES



"onDocumentSelect" property of my drive picker is below:


app.popups.ModalLoadingIndicator.visible = true;
var key = widget.datasource.item._key;
var id = result.docs[0].id;
google.script.run.withSuccessHandler(function() {
app.datasources.products.load(function() {
app.popups.ModalLoadingIndicator.visible = false;
});
}).autoAddimage(key, id);



which is referring to this server script:


function autoAddimage(key, id) {
var record = app.models.products.getRecord(key);
record.imageID = id;
record.ImageUrl = Drive.Files.get(id).webContentLink;
app.saveRecords([record]);
}



For some reason, ImageUrl comes as blank. I tried selecting image from both personal drive and team drive folders, it doesn't work. What I want to achieve seems pretty simple, for some reason i couldn't figure it out.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to input without newline? (Python)

C++ thread error: no type named ‘type’ MINGW

Analog for TagView in flutter