Created
November 27, 2018 10:05
-
-
Save ahmedam55/da751337ca7de3cbf2245506a2b61a8c to your computer and use it in GitHub Desktop.
Embedding or sharing an image or photo uploaded to Google Drive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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