How to update a thumbnail? - google-drive-api

The new thumbnail feature works great when inserting a new file.
Is there a way to update the thumbnail for an existing file?
I did not manage to update the thumbnail (in Java) using the files().patch() or files().update() methods.
I don't get any error message, but the thumbnail in Google Drive is just not changing when uploading a new thumbnail.
File file = drive.files().get(fileId).execute();
String encodedImage = Base64.encodeBase64URLSafeString(imageData);
Thumbnail thumbnail = new Thumbnail();
thumbnail.setImage(encodedImage);
thumbnail.setMimeType("image/png");
file.setThumbnail(thumbnail);
drive.files().update(fileId, file).execute();
Update:
As I am using exactly the same code for inserting a file with thumbnail (which works) and updating the file as shown in the code snippet above (which will not update the thumbnail) it may make sense that you use my app to perform both operations.
Login to www.ultradox.com
Copy one of the examples.
This will create a new file on your Google Drive with the correct thumbnail
(as it triggers the insert file method with thumbnail).
Click on the "Customize" button
Scroll down and click on the thumbnail image to upload a new thumbnail
= Thumbnail not changed, but update should be triggered.
So probably something shows up in your logs?

The current behavior is that updates to metadata alone do not allow a change in the thumbnail. So changes to the metadata alone do not take the thumbnail change. I am not sure this is the best behavior, and we will try to improve it to:
Allow the thumbnail update
Report an error rather than appearing to succeed

Related

Is there any way to change a Google Slides presentation without reloading it?

I'm basically trying to build a game board. For simplicity's sake, imagine a Jeopardy! board. I'd like to be able to click on a square (imagine it says $200) and go to the question set for that square. Then, when I return to the main board, I'd like that square that I clicked on ($200) to be blank, so I know I've already clicked it.
I want to be able to do this in a full screen presentation, without having to reload the slideshow at all.
I'm thinking, hoping, I could do a script that would just straight-up replace the image of a screen with text on it, to an image of a blank screen, but I'd also be okay with building the slide with two layers of images - one with text above one without - and deleting the top layer when it's clicked.
Click on and it becomes this:
Replacing the image via script can be easily done by using the following script:
function myFunction() {
var image = SlidesApp.getActivePresentation().getSlides()[0].getImages()[0];
// Get the Drive image file with the given ID.
var driveImage = DriveApp.getFileById('File ID of the new image');
image.replace(driveImage);
}
But unfortunately, assigning an image to act as a button to run script is only available on Google Spreadsheet. And by further checking it seems somebody already submitted a Feature Request for such a feature to be implemented on Google Slides as well.
References:
https://developers.google.com/apps-script/reference/slides/image#replace(BlobSource)

Create a new drawing and set the page size

I use Google Drawings to annotate screenshots. Currently, my workflow is to create a new Drawing, and then set the page size via File > Page Setup > Custom.
Using the Google Apps Script, is there a way to automate this workflow? For example, I could create a simple UI, with two text boxes and a button. I enter width and height in the text boxes and then click the button to create the new Drawing.
You can create Files in DriveApp from a blob source using the .createFile() method.
One parameter in the blob object is MIME type, and there is a drawings option you can use. It doesn't look like you can pass size data into the file, though.

What is the right way to put a Drive image into a Sheets cell programmatically?

I have a WebApp that collects work site data into a Google Sheets spreadsheet and also collects work site photos into a Google Drive folder that I create for each job. Some, but not all, of the photos must be viewable in a cell in Google Sheets, such that the sheet can be printed as part of a job completion report.
I use Google Picker to upload files to the folder specific to the work site job. I am unsure of the best way to use them from there.
I have had success setting a cell formula such as =IMAGE("hllp://i.imgur.com/yuRheros.png", 4, 387, 422), but only with images pulled from elsewhere on the web.
Using the permalink trick like this =IMAGE("hllp://drive.google.com/uc?export=view&id=0B8xy-TdDgbjiFoOldUlLT091NXM", 4, 387, 422) does not work; I think it won't tolerate the URL redirect that Google does on those links.
The other way I have read about, but not tried yet, is to write the actual blob into the cell. However, I suspect I will lose any control over subsequent formatting of the report.
Perhaps I am going to need to record the image specification in several ways in several cells:
its Google Drive hash key
its dimensions
its alternate location in imgur.com (or similar)
its blob
Is there a programmatic way to get Google's redirected final URL for an image, equivalent to opening the image and copying the URL by hand? Could one trust it for ever, or does it change over time?
Update : I am wrong about =IMAGE("hllp://drive.google.com/uc?export=view&id=0B8xy-TdDgbjiFoOldUlLT091NXM", 4, 387, 422) not working. It is essential that the image be shared to "anyone with the link", even if the owner of the spreadsheet is also the owner of the image.
I am going to go with recording just 1.hash key and 2.dimensions as my solution, but I'd be delighted to know if anyone else has a better idea.
Assuming you get the ID of your image in your drive, you can use a code like below to insert an image in the last row of a sheet (the url is a bit different than usual):
...
var img = DriveApp.getFileById('image ID');// or any other way to get the image object
var imageInsert = sheet.getRange(lastRow+1, 5).setFormula('=image("https://drive.google.com/uc?export=view&id='+img.getId()+'")');// in this example the image is in column E
sheet.setRowHeight(lastRow+1, 80);// define a row height to determine the size of the image in the cell
...
I would suggest that you carefully check the sharing properties of the files you are trying to show : they must be set to "public" of moved in a folder that is also "publicly shared"
I made a two lines script to use the share link of an image in Google Drive.
Go to Tools > Script editor.
Copy, paste the following code
Save
function DRIVE_IMAGE(link){
return link.replace("open?", "uc?export=download&");
}
Using the script :
Copy the Get shareable link of your image in Google Drive (Maybe you need to set the share preference to Public on the web).
Go to a Google sheets cell.
Enter the formula
=IMAGE(DRIVE_IMAGE("COPIED_LINK"))
We build a lot of sheets with images and use the static link available in the google album archive { https://get.google.com/albumarchive/... } rather than the dynamic link in google photos. the link in the archive normally ends in "-rw" which limits view-ability to some with whom the doc is shared with. Deleting "-rw" from the end of the link seems to help.

Image in GridViewItem on previous Page blocking file access

I have a Page Ingredients.xaml with a GridView. This GridView displays a list of Ingredient objects. For each item, an image is displayed by binding to a string property of the Ingredient object containing the file's path (in the app's local folder).
When I click on an item, the app navigates to Ingredient.xaml, a details page, where the image as well as all the details are displayed. There is functionality to set a new image or replace/remove the current one.
When there is no image yet, everything works like a charm. However, as soon as a file exists already, I get the following error when trying to either delete or replace the current file:
"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))".
At first I thought the Image in Ingredient.xaml was the issue, since it was still showing the image I was trying to delete. So i added the following line to the code:
this.ingredientImage.Source = null;
The code was still throwing the exception, though. So I tried something else: I removed the Image from the GridView in Ingredients.xaml. The only place the image is shown not is in Ingredient.xaml. When I try to replace/delete the image, Image.Source is set to null and the file is successfully replaced/deleted.
Apparently the Image in the GridView on the previous Page is still blocking the file, but I have no idea how I could release the file when I navigate away.

get image data from custom report item(ssrs control)

Does anybody know how to get image data from inside custom report item?
I want to enable users of my component to set image (background image for example) for the component to use. I've managed to create property with ImageSource type, but I reason that I need to read Source and Value, and than retrive the image data itself(since there is nothing in the ImageSource interface to access it).
I suspect that there should be a common interface for all types of sources, but if I need to use something like EmbeddedImageCollection that is also fine.
Thanks!
in Short : View Code and copy and paste the tag into the embedded images tag