Convert a Google Drive image URL to a direct link via the Google Sheets connector

You are using Google Drive to host your images and want to use the Google Sheets connector to import your content?

A manipulation is necessary to allow you to automatically generate usable links for your images, so they can be added correctly in Wemap Pro.

E.g.: if you want to import specific images for your points on Wemap Pro and these images are stored on Google Drive, each one must have a specific link to be used.


🧮 Option 1: Use a formula in Google Sheets


You can automatically transform a Google Drive link into a direct displayable link via a formula in your file.

E.g.:

  • Classic Google Drive link:
https://drive.google.com/file/d/IDIMAGE/view?usp=sharing
  • Direct link:
https://drive.google.com/uc?export=view&id=IDIMAGE

🧰 Procedure:

In Google Sheets:

  1. Add a new empty column next to the one containing your Google Drive links

E.g.: if your links are in column C, create your new column D.


  1. Paste the following formula into the first empty cell of the new column

E.g.: in cell D2, with D1 being the one containing the column label.

=IF(REGEXMATCH(C2, "drive.google.com\/file\/d\/"), "https://drive.google.com/uc?export=view&id=" & REGEXEXTRACT(C2, "[-\w]{25,}"), "")

📌 Note:

Depending on the format and content of your file, replace "C2" with the cell number that contains your Google Drive link.

E.g.: if your links are in column E, you should enter "E2".

  1. Drag the cell down to apply the formula to all rows.

  1. Use this new column, with the direct links, for display in your tools (map, database...).


đŸ’ģ Option 2: Automate with a script


If you prefer a method without formulas (simpler in the long term), you can add a script to your Google Sheets file.

It will automatically detect any new link pasted in a column and generate a direct link in the relevant column.


🧰 Procedure:

In Google Sheets:

  1. Click on "Extensions" > "Apps Script".

  1. Delete all existing content and paste the following script:
function onEdit(e) {
  const sheet = e.source.getActiveSheet();
  const range = e.range;

  const sourceColumn = 3;
  const targetColumn = 4;

  if (range.getColumn() === sourceColumn && range.getRow() > 1) {
    const driveUrl = range.getValue();
    const outputCell = sheet.getRange(range.getRow(), targetColumn);

    const regex = /https:\/\/drive\.google\.com\/file\/d\/([-\w]{25,})/;
    const match = driveUrl.match(regex);

    if (match) {
      const fileId = match[1];
      const directUrl = `https://drive.google.com/uc?export=view&id=${fileId}`;
      outputCell.setValue(directUrl);
    } else {
      outputCell.setValue("");
    }
  }
}

â„šī¸ Note:

  • Adjust the column numbers according to your needs:
    • sourceColumn = 3 corresponds to column C (column containing the Google Drive link)
    • targetColumn = 4 corresponds to column D (column containing the direct link)

  • The line outputCell.setValue(""); appears empty if the link is not valid.
  1. Click on "Save" and give a name to the project.

E.g.: "DriveLinksConversion".


âžĄī¸ Each time a Google Drive link is added to the source column, a direct link is automatically generated in the adjacent column.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us