Skip to content

Instantly share code, notes, and snippets.

@ahmedam55
Created November 27, 2018 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedam55/da751337ca7de3cbf2245506a2b61a8c to your computer and use it in GitHub Desktop.
Save ahmedam55/da751337ca7de3cbf2245506a2b61a8c to your computer and use it in GitHub Desktop.
Embedding or sharing an image or photo uploaded to Google Drive.
# Usage: googleImage https://drive.google.com/file/d/1ohKYjS7FxgkHCqdhP5gpYPMJN8xueqF2/view?usp=sharing
# Output: https://doc-0c-a4-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/50g94rphugajflevka9unjmgidqmudio/1543312800000/16295291601680688896/*/1ohKYjS7FxgkHCqdhP5gpYPMJN8xueqF2
function googleImage {
# Replace the parts around sharable link of google drive to extract the fileId
local fileId=$(echo 'https://drive.google.com/file/d/1ohKYjS7FxgkHCqdhP5gpYPMJN8xueqF2/view?usp=sharing' | sed 's/https:\/\/drive.google.com\/file\/d\///g' | sed 's/\/view\?usp=sharing//g')
# Prepend the exportable link
local url="https://docs.google.com/uc?id=$fileId"
# Get public generated url
local publicUrl=$(curl -Ls -o /dev/null -w %{url_effective} $url)
echo $publicUrl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment