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
Share:
23,123
ThePumpkinMaster
Author by

ThePumpkinMaster

Updated on July 09, 2022

Comments

  • ThePumpkinMaster
    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
    ThePumpkinMaster almost 8 years
    I'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
    Brad almost 8 years
    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.
  • CAMOBAP
    CAMOBAP about 7 years
  • Szundi
    Szundi about 4 years
    did not try on windows, but genius :)
  • Eric Tobias
    Eric Tobias almost 4 years
    Unfortunately, the provided instruction page no longer exists.
  • Brad
    Brad almost 4 years
    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)
  • tbeu
    tbeu over 3 years
    Works as expected when pasted to a Git Bash on Win 10.
  • Nico
    Nico almost 3 years
    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!