Hosting images used in your ads on Google Drive is an easy way to get started quickly with a product feed for Automated Ads or a Dynamic Ads catalog. However, there are a couple of things you need to take into account when doing this:
- To use files hosted on Google Drive, the files have to be accessible publicly to everyone in Google's sharing settings.
- Only files up to 100MB in size can be downloaded directly from Google Drive.
- This is because Google automatically scans shared files for viruses whenever they're accessed, and files larger than 100MB will not be automatically scanned. Instead, accessing the file leads to a warning page, and our automated download systems cannot access the file itself.
When hosting images on Google Drive, the default sharing option only allows for viewing the images online, but not downloading them. This means that if you use the default sharing URLs or images for your feed, the images will not be downloaded and will cause an error. This can be resolved by changing the sharing URLs as follows:
Change the URLs from this structure: https://drive.google.com/file/d/FILE_ID/edit?usp=sharing
to this structure: https://drive.google.com/uc?export=download&id=FILE_ID.
The FILE_ID is the long string of numbers and letters in the middle of the sharing URL.
To test that the change successfully worked, simply follow the edited link URL in your browser. If it doesn't open a new window or tab but instead your browser starts to download the file, everything should be working as intended.
An automated option
You can automatically modify the URLs by using the CONCATENATE and REGEXEXTRACT functions in a sheet. When doing this, the original URLs would be in one column, and the modified URLs in another. For example, if you have the URLs in the A column starting from A2, you can insert the following expression into B2 and then copy it to other cells as well:
=CONCATENATE("https://drive.google.com/uc?export=download&id=",REGEXEXTRACT(A2,"d/(.*)/"))
Get download links for all files within a Google Drive folder
ℹ️ Prerequisite: The sharing setting for all the files in the folder needs to be Anyone on the internet with this link can view. If the files are not available publicly via the link, Smartly.io will not be able to access them.
- Create a new Google spreadsheet, and check that the sheet is named "Sheet1".
- Enter the Google Drive folder URL into cell A1.
- To get the folder URL, navigate into the folder and copy the URL from the address bar. The URL is in this format: https://drive.google.com/drive/folders/FOLDER_ID
- Remove any additional parameters from the URL, such as "?usp=sharing" from the folder link (basically anything after FOLDER_ID and starting with "?").
- Now proceed to implement the script. First, go to Extensions > Apps Script while in your Sheets window.
- Remove the prefilled myFunction, and then copy the script provided below and paste it in the editor.
function getLinks() {
//Google Drive Folder link has to be added in cell A1, eg: https://drive.google.com/drive/folders/<FOLDER_ID>
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
sheet.getRange("A2:C").clear();
sheet.appendRow(["File name","File ID","Download URL"])
var folderId = sheet.getRange("A1").getValue().split("folders/")[1];
var folder = DriveApp.getFolderById(folderId);
var contents = folder.getFiles();
var cnt = 0;
var file;
while (contents.hasNext()) {
var file = contents.next();
cnt++;
data = [
file.getName(),
file.getId(),
"https://drive.google.com/uc?export=download&id="+file.getId()
];
sheet.getLastRow();
sheet.appendRow(data);
};
}; - Run the function by selecting Run > Run Function > getLinks from the top bar.
- Now you have to authorize the sheet to access your Drive. It needs the access so it's able to fetch the file names from the folder.
Now when you go back to the sheet, you should see the downloadable links, file names, and file IDs in the view.
Optionally, you can also create a button that automatically runs the script so that you don't have to open the script editor to run it:
- In Sheet1, click Insert > Drawing.
- Create some kind of a drawing, for example, a text box that says "Get links".
- In the top-right corner of the drawing, click the three dots and click Assign script, write getLinks into the dialog and click OK.
- Click the drawing that you just assigned the getLinks script to. You should see the sheet populating with the data from the folder.
ℹ️ Note: The function might be rather slow sometimes due to delay in the script's communication with Google Drive, but it should eventually get the data if you have access to the folder.
Download all images from a website
You can easily download all images from a website by using, for example, https://imagecyborg.com.