Today I Learned
Search…
Extract file id from drive shareable link
I host my blog images on Google Drive sometimes, the normal shareable link is not the actual image source. Instead this is :
https://drive.google.com/uc?export=view&id=<INSERT-ID>
INSERT_ID is the file id (in the shareable link)which is higlighted below
here is a bash script to convert the link.
1
#!/usr/bin/env bash
2
​
3
str="$1"
4
# remove everything after the last /
5
remove_last=${str%/*}
6
# get everything after the last /
7
get_last=${remove_last##*/}
8
echo "https://drive.google.com/uc?export=view&id=$get_last"
Copied!
You can now use it in <img> src
Copy link
Edit on GitHub