Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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