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.
Asked
Active
Viewed 3.2k times
2 Answers
11
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

Chris
- 939
- 2
- 11
- 22
-
Works as expected when pasted to a Git Bash on Win 10. – tbeu Dec 08 '20 at 19:19
-
I 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! – John Grant Jul 25 '21 at 17:53
-
This doesn't work with `https://onedrive.live.com/?authkey=%21AOaPhONxGCKIlrg&cid=910FC0C1DD8E9B39&id=910FC0C1DD8E9B39%21163&parId=910FC0C1DD8E9B39%21104&o=OneUp`. – HappyFace Oct 07 '22 at 08:19
-
@HappyFace Your link provides already direct link to the file: https://m7bcfg.db.files.1drv.com/y4mTguy9KYeKVM8zeNZOJZgfW7-NJ5kiiLwqEmV9X8MALN1fC4XeVOa0YJKiKR7Di_Z_aoUap3SmvhC4mjdhI8WNsZc_TOF5HGJ4v2Um2I7RvYKHDUlM1kLyG2M6AgnuTRnKGiqDvuIcRLVQ5RiAGbI0SNr3mriWKXFbE8jA4JVQL2f1AnPTlfDNs6USNlu5tF4twQmvEvuntitakYrGhGUHw? – DonJ Oct 08 '22 at 10:29
9
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

Brad
- 4,089
- 2
- 16
- 26
-
I'm sorry, how did you get that link exactly? The link uses a sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1". This is different than the link I have of https://1drv.ms/w/s!AqmFiI7maXrRgT7PGcK_7JyZlBco – ThePumpkinMaster Jun 22 '16 at 00:49
-
the `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. – Brad Jun 22 '16 at 16:47
-
8http://rextester.com/QNSY6325 this will help to build such url (according https://github.com/OneDrive/onedrive-api-docs/blob/master/shares/shares.md) – CAMOBAP Feb 07 '17 at 17:27
-
-
Thanks 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) – Brad Jul 28 '20 at 19:41