Tuesday, January 17, 2017

OneDrive 2017 Direct File Download URL Maker






Microsoft OneDrive Direct File Download URL Maker




<iframe src="https://onedrive.live.com/embed?cid=8F99649728BEB2F3&resid=8F99649728BEB2F3%211010&authkey=AFo8ZQ_-qj84DEQ" width="98" height="120" frameborder="0" scrolling="no"></iframe>  see instructions below, if you don't know how. NOTE : For images there an extra step below.



https://onedrive.live.com/embed?cid=8F99649728BEB2F3&resid=8F99649728BEB2F3%211010&authkey=AFo8ZQ_-qj84DEQ and populate the text-box below. To proceed click "Get Download Link" button.



4. Now, Click on Get Download Link button.


Text-box will be highlighted so you can copy the full link. To copy, right-click and choose  "Copy" or simply (ctrl-c) to copy link. Note: Entire URL is automatic selected for your convenience.





 


How to get a Microsoft OneDrive Embed Code detailed instructions



  1. Goto OneDrive (https://onedrive.live.com/)
  2. Upload you file

  3. Right-click to "Embed" your uploaded file 

  4. Click Generate HTML Button.

  5. Copy and Paste HTML Code to Notepad

  6. Copy the all the embed code ie. <iframe src="https://onedrive.live.com/embed?cid=..." >...</iframe> and paste into  above.
  7. Done!


For Images, you have to do an extra step




  1. Right-click to "Share" your uploaded file

  2. Click Copy button. Updated Jan 01, 2017 API change.


    This will produce a share URL that looks like this, 

    https://1drv.ms/i/s!AvOyviiXZJmPlSc1CjtKuwc_gqVu
  3. Paste share URL into http://www.linkexpander.com/ and copy that URL. 



    The resulting Uncovered URL is in the format we need, and look like this.

    https://onedrive.live.com/redir?resid=8F99649728BEB2F3!2727&authkey=!ADUKO0q7Bz-CpW4&ithint=photo%2cjpg


  4. Paste "Uncovered URL" link into 3.1 OneDrive File Embed Link text-box above
    and click 4. "Get Download Link" button above.
  5. Right-click and choose "Select all" and "Copy".
  6. Paste the OneDrive Share Direct Download Link in emails instead.
  7. Done
OR for images only
  1. Updated June 07, 2016 API change!

    Right-click on image and select Embed. The Copy the URL to embed image now gives you direct download URL, but is super long.

    So you do not need to do the above! 

Using OneDrive as a CDN


Bonus : For images, read Using OneDrive as a Content Delivery Network (CDN) plausibility post.

A note about Sharing PDFs

Google Chrome Warning: Very large PDF files do not preview in Chrome
PDF files approx. over 100Mb in size, do not preview in Chrome, and you get a splash page to "For the best experience, open this PDF portfolio in Adobe Acrobat or Adobe Reader"

You have to save the file first then open in Adobe Acrobat/Reader.




10 comments:

  1. Unfortunately, it seems that this tecnique can't be used to retrieve files programatically via JS code, because OneDrive servers doesn't send response header "Access-Control-Allow-Origin" for a such kind of direct URLs...

    ReplyDelete
  2. I just found, how to get "super" direct link to OneDrive shared file, folowing which you will receive Access-Control-Allow-Origin header required to conform CORS policy while accessing OneDrive shared files from JavaScript in your Browser.
    1. You need to generate OneDrive embed link.
    2. Base64 encode it and prefix with "u!"
    3. Go to Graph Explorer (It seems like they call the whole MS Web services API as "Microsoft Graph") - OneDrive REST API official test App at https://developer.microsoft.com/en-us/graph/graph-explorer
    4. Login there to yours Microsoft Account and Execute this query:
    https://graph.microsoft.com/v1.0/shares/u!{your_base64_encoded_onedrive_file_embed_link}/root/
    5. Copy content of the response JSON object field named "@microsoft.graph.downloadUrl".

    That's it - appears simplier than it seems.
    P.S. But I didn't tested yet how long these URLs will be valid.

    ReplyDelete
    Replies
    1. It's sad, but it seems these links lives just about a 24 hours or so.(

      Delete
    2. Have you examined the OneDrive API - https://dev.onedrive.com/items/download.htm? Does this work?

      Delete
  3. Haven't tested yet, but, if I got this right, you have to authorize your web app before it could get any items even shered ones, so it's not so interesting, because you have to store and refresh authorization token and therefor you have to force users to Oauth your app to their's OneDrives to make things work.

    ReplyDelete
  4. You are a life saver. This worked nicely.

    I cannot believe I can't just get the link directly from One Drive. Completely bonkers!!

    ReplyDelete
  5. In OneDrive click on the picture you need a link for. You then get a few more options along the top bar, select 'View Original' from the ribbon. In the next window you can then copy the long link from the address bar (up to .jpg) and you're good to go.

    ReplyDelete
  6. Great post, it works perfectly for me, just added a downlad button to a wordpress site an it downloads directly from onedrive. Excelent!

    ReplyDelete