Direct download link to OneDrive file?
23,123
Solution 1
If you follow the instruction here you can generate a URL that will act on the shared item, including being able to get its content.
In your case the URL would look like https://api.onedrive.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL3cvcyFBcW1GaUk3bWFYclJnVDdQR2NLXzdKeVpsQmNv/root/content
Solution 2
You can also add a simple function to your .bashrc that will do the same trick:
onelink() { echo -n "$1"|base64|sed "s/=$//;s/\//\_/g;s/\+/\-/g;s/^/https:\/\/api\.onedrive\.com\/v1\.0\/shares\/u\!/;s/$/\/root\/content/"; }
Result is the same:
$ onelink 'https://1drv.ms/w/s!AqmFiI7maXrRgT7PGcK_7JyZlBco'
https://api.onedrive.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL3cvcyFBcW1GaUk3bWFYclJnVDdQR2NLXzdKeVpsQmNv/root/content
Author by
ThePumpkinMaster
Updated on July 09, 2022Comments
-
ThePumpkinMaster almost 2 years
A OneDrive sharable link looks like this: https://1drv.ms/w/s!AqmFiI7maXrRgT7PGcK_7JyZlBco. How do I get the direct download link version of this? I know with a onedrive.live/redir?<...> link I can just replace the 'redir' with 'download', but how do I do that for a link that looks like the one above? Thanks.
-
ThePumpkinMaster almost 8 yearsI'm sorry, how did you get that link exactly? The link uses a sharingUrl = "onedrive.live.com/…". This is different than the link I have of 1drv.ms/w/s!AqmFiI7maXrRgT7PGcK_7JyZlBco
-
Brad almost 8 yearsthe
u!asfdjlasdkfjsa
segment of the URL above is actually a Base64 encoded version of your URL. Take a look at the instructions I referenced and it should explain the process. -
CAMOBAP about 7 yearsrextester.com/QNSY6325 this will help to build such url (according github.com/OneDrive/onedrive-api-docs/blob/master/shares/…)
-
Szundi about 4 yearsdid not try on windows, but genius :)
-
Eric Tobias almost 4 yearsUnfortunately, the provided instruction page no longer exists.
-
Brad almost 4 yearsThanks for pointing that our @Eric, I've updated the link. It calls out the Microsoft Graph endpoint but the same pattern works for
api.onedrive.com
with minor tweaks (hostname etc) -
tbeu over 3 yearsWorks as expected when pasted to a Git Bash on Win 10.
-
Nico almost 3 yearsI had to make a minor change in my shell. I’m on Apline Linux and installed bash shell. The regular expression was broken with the error ‘ sed: bad regex '\+': Repetition not preceded by valid expression’ until I added the -r switch to sed. Thanks!