I have a public url for iCloud file, how can I get a DIRECT link to download in iOS?

I can generate public URLs for iCloud files. e.g. https://www.icloud.com/documents/dl/?p=3&t=BAKsXkcDP-p8sdTS8NgBLWRQxE281oe4hogA

Accessing such a URL from a browser, I see the landing page, and soon after that the file automatically loads. Good.

However, I want to download this file from my iOS application (with NSURLConnection). How can i do this? Maybe ... a) handle the html headers to somehow determine the direct URL? b) intercept the redirect / update that launches the download in the browser? c) somehow mimic the browser to trigger a download?

thanks

PS. please give me an idiotic answer - I don't know about html etc.

Here is the html response I get for the indirect URL above:

var SC_benchmarkPreloadEvents = {headStart: new Date (). getTime ()}; β†’ iCloud - Loading ... window.SC = window.SC || {MODULE_INFO: {}, LAZY_INSTANTIATION: {}}; SC.buildMode = "production"; SC.buildNumber = "1FCS22.32292"; SC.buildLocale = "EN-US"; String.preferredLanguage = "EN-US"; window.SC = window.SC || {MODULE_INFO: {}, LAZY_INSTANTIATION: {}}; SC._detectBrowser = function (userAgent, language) {var version, webkitVersion, browser = {}; UserAgent = (UserAgent || navigator.userAgent) .toLowerCase (); language = language || navigator.language || navigator.browserLanguage; version = browser.version = (userAgent.match (/.* (?: rv | chrome | webkit | opera | ie) /: ([);] | $) /) || []) [1]; webkitVersion = (userAgent.match (/ webkit /(.+?)/) || [] [[1]; browser.windows = browser.isWindows = !! / windows / .test (userAgent); browser.mac = browser .isMac = !! / macintosh / .test (userAgent) || (/ mac os x / .test (userAgent) & &! / like mac os x / .test (userAgent)); browser.lion = browser.isLion = !! (/ mac os x 10_7 / .test (userAgent) & &! / like mac os x 10_7 / .test (userAgent)); browser.iPhone = browser.isiPhone = !! / iphone / .test (UserAgent); browser.iPod = browser.isiPod = !! / bid / .test (UserAgent); browser.iPad = browser.isiPad = !! / Ipad / .test (UserAgent); browser.iOS = browser.isiOS = browser.iPhone | | browser.iPod || browser.iPad ;? Browser.android = browser.isAndroid = !! / Android / .test (UserAgent); browser.opera = / opera / .test (UserAgent) Version: 0; browser.isOpera = !! browser.opera; browser.msie = / MSIE / .test (UserAgent) && browser.opera version :? 0; browser.isIE = !! browser.msie; browser.isIE8OrLower = !! (browser.msie && ParseInt ( browser.msie, 10) <= 8); browser.mozilla = / Mozilla / .test (User Agent) & & / (compatible | WebKit | MSIE) / test (UserAgent) version:.? 0; browser.isMozilla = !! browser.mozilla; browser.webkit = / WebKit / .test (UserAgent) webkitVersion: 0; browser.isWebkit = !! browser.webkit; browser.chrome = / chrome / .test (UserAgent) version: 0; browser.isChrome = !! browser.chrome; browser.mobileSafari = / apple * mobile /.test(UserAgent) && browser.iOS webkitVersion:.? 0; browser.isMobileSafari = !! browser.mobileSafari; browser.iPadSafari = browser.iPad && browser.isMobileSafari webkitVersion: 0; browser.isiPadSafari = !! browser.iPadSafari; browser.iPhoneSafari = browser.iPhone && browser.isMobileSafari webkitVersion: 0; browser.isiPhoneSafari = !! browser.iphoneSafari; browser.iPodSafari = browser.iPod && browser.isMobileSafari webkitVersion: 0; browser.isiPodSafari = !! browser.iPodSafari; browser.isiOSHomeScreen = browser.isMobileSafari & &! / / apple * mobile * safari /.test(UserAgent) ..; browser.safari = browser.webkit && browser.chrome && browser.iOS && browser.android webkitVersion:!? 0; browser.isSafari = !! browser.safari; browser.language = language.split ("-", 1) [0]; browser.current = browser.msie "MSIE": browser.mozilla "Mozilla": browser?.? chrome "chrome": browser.safari "safari": browser.opera "Opera": browser.mobileSafari "mobile-safari": browser.android "android": "unknown"; ?? return browser}; SC.browser = SC._detectBrowser (); if (typeof SC_benchmarkPreloadEvents! == "undefined") {SC.benchmarkPreloadEvents = SC_benchmarkPreloadEvents; SC_benchmarkPreloadEvents = undefined} else {SC.benchmarkPreloadEvents = {headStart: new Date (). GetTime ()}} SC.setupBodyClassNames = function () {var el = document.body; if (! El) {return} var browser, platform, shadows, borderRad, classNames, style ;? browser = SC.browser.current; platform = SC.browser.windows "window": SC.browser.mac "mac": "other-platform"; style = document.documentElement.style; shadow = (! style.MozBoxShadow == undefined) || (! style.webkitBoxShadow == undefined) || (! style.oBoxShadow == undefined) || (style.boxShadow == undefined!); borderRad = (style.MozBorderRadius! == undefined) || (style.webkitBorderRadius! == undefined) || (style.oBorderRadius! == undefined) || (style.borderRadius! == undefined); classNames = el.className? el.className.split ("): []; if (shadows) {classNames.push (" box-shadow ")} If (borderRad) {classNames.push (" Border-Rad ")} classNames.push (browser) ; if (browser === "chrome") {classNames.push ("safari")} classNames.push (platform); var ieVersion = parseInt (SC.browser.msie, 10); if (ieVersion) {if (ieVersion === 7) {classNames.push ("ie7")} More {if (ieVersion === 8) {classNames.push ("ie8")} more {if (ieVersion === 9) {classNames.push ( "IE9")}}}} if (SC.browser.mobileSafari) {classNames.push ("mobile-safari")} if ("createTouch" in the document) {classNames.push ("touch")} el.className = classNames.join ("")}; (function () {var styles = []; if (window.devicePixelRatio == 2 || window.location.search.indexOf ("2x")> - 1) {styles = [ "/applications/documents/downloads/EN-US/1FCS22.32292/ stylesheet@2x-packed.css "]; SC.APP_IMAGE_ASSETS = ["/ applications / documents / sproutcore / desktop / en -us / 1FCS22.32292 / stylesheet-no-repeat@2x.png "," / applications / documents / coreweb / views / en-us / 1FCS22. 32292 / stylesheet-no-repeat@2x.png "" / applications / documents / sproutcore / ace / en - us / 1FCS22.32292 / stylesheet-no-repeat@2x.png "," / applications / documents/SproutCore/ace/en-us/1FCS22.32292/ stylesheet-no-repeat@2x.png "," / applications / documents / sproutcore / ace / en -us / 1FCS22.32292 / stylesheet-repeat-y@2x.png "," / applications / documents / download / en -us / 1FCS22.32292 / stylesheet-no-repeat@2x.png "," / applications / documents / download / en -us / 1FCS22.32292 / stylesheet-repeat-x@2x.png "]} More {styles = [" /applications/documents/downloads/EN-US/1FCS22.32292/ stylesheet-packed.css "]; SC.APP_IMAGE_ASSETS = ["/applications/documents/SproutCore/tables/EN-US/1FCS22.32292/stylesheet-no-repeat.png", "/applications/documents/coreweb/views/an-us/1FCS22.32292 / stylesheets, non-repeat.png "" /application/documents/SproutCore/ac/an-as/1FCS22.32292/stylesheet -no-repeat.png "," / application / documents / SproutCore / ac / an- us / 1FCS22.32292 / style sheet-repeat-x.png "" /applications/documents/SproutCore/ac/an-as/1FCS22.32292/ style sheet-repeat-y.png "," / applications / documents / downloads / en- us / 1FCS22.32292 / style sheet-no-repeat.png "," /applications/documents/downloads/EN-US/1FCS22.32292/ style sheet-repeat x.png "]} var head = doc ument.getElementsByTagName ("head") [0], len = styles.length, idx, css; for (idx = 0; idxSC.benchmarkPreloadEvents.headEnd = new Date (). getTime (); SC.benchmarkPreloadEvents.bodyStart = new Date (). getTime (); if (SC.setupBodyClassNames) {SC.setupBodyClassNames ()}; SC.benchmarkPreloadEvents.bodyEnd = new Date (). GetTime ();

+4
source share
3 answers

As of July 2012, it seems to be working. But there is no guarantee that the apple will not change its scheme for creating them, and it is possible that they will consider this as a private API and reject your application. Therefore, use at your own risk .

URL has two important parameters: p and t . The first seems to identify the server, and the second identifies the actual file. A direct download link is made by connecting these values ​​to this URL:

 https://p[p]-ubiquityws.icloud.com/ws/file/[t] 

Looking at your example:

 https://www.icloud.com/documents/dl/?p=3&t=BAKsXkcDP-p8sdTS8NgBLWRQxE281oe4hogA 

p 3 and t - BAKsXkcDP-p8sdTS8NgBLWRQxE281oe4hogA . So your direct download link will be

 https://p3-ubiquityws.icloud.com/ws/file/BAKsXkcDP-p8sdTS8NgBLWRQxE281oe4hogA 

Whenever I posted a link to iCloud, p was 01 ; so it’s possible that you may need a null value of your value, in which case your URL will be

 https://p03-ubiquityws.icloud.com/ws/file/BAKsXkcDP-p8sdTS8NgBLWRQxE281oe4hogA 

It would be great to know if this is necessary.

+2
source

It seems like a heavy lift is performed by the file it refers to:

https://www.icloud.com/applications/documents/download/en-us/1FCS22.32292/javascript-packed.js

I would start looking for a file name, etc.

+1
source

The links are different in iCloud Drive / iOS8, but you can still get a direct link to the files.

Original link:

 https://www.icloud.com/attachment?u=https%3A%2F%2Fms-eu-ams-103-prod.digitalhub.com%2FB%2FATmkKK8ju8SRwQqDoEFKJzbRsxiuAXQ3PBcJBXw1Qot9jz68TkqjiiNu%2F%24%7Bf%7D%3Fo%3DAtenENR8OcvlNq6JMa331mr-8gCreXxwcfgQ26B5gFKo%26v%3D1%26x%3D3%26a%3DBclucinSeKmFAy2GJg%26e%3D1413787013%26k%3D%24%7Buk%7D%26r%3D567CC38A-FD1B-4DE6-B11B-4166A5669E1B-1%26z%3Dhttps%253A%252F%252Fp03-content.icloud.com%253A443%26s%3DlO5SolOouS9qhYz1oIxKDoGtMpo%26hs%3DovfPXj3b9XXz9lWKChBmyNq_cug&amp;uk=OXDCcLTETbvUcOKdJ-vTdQ&amp;f=Testdatei.vrphoto&amp;sz=1212622 

The URL is decoded to be more readable:

 https://www.icloud.com/attachment?u=https://ms-eu-ams-103-prod.digitalhub.com/B/ATmkKK8ju8SRwQqDoEFKJzbRsxiuAXQ3PBcJBXw1Qot9jz68TkqjiiNu/${f}?o=AtenENR8OcvlNq6JMa331mr-8gCreXxwcfgQ26B5gFKo&v=1&x=3&a=BclucinSeKmFAy2GJg&e=1413787013&k=${uk}&r=567CC38A-FD1B-4DE6-B11B-4166A5669E1B-1&z=https%3A%2F%2Fp03-content.icloud.com%3A443&s=lO5SolOouS9qhYz1oIxKDoGtMpo&hs=ovfPXj3b9XXz9lWKChBmyNq_cug&amp;uk=OXDCcLTETbvUcOKdJ-vTdQ&amp;f=Testdatei.vrphoto&amp;sz=1212622 
  • Save text between '? u = 'and' & uk = 'as NSMutableString
  • Save the information after 'uk =' and 'f =' as NSStrings
  • In the first line, replace the text '$ {f}' with the string 'f =' and replace the text '$ {uk}' with the string 'uk ='
  • If you need file size for any reason, this is the number after 'sz =', but this is not necessary for the last link

Voila, here is your direct link to the file:

 https://ms-eu-ams-103-prod.digitalhub.com/B/ATmkKK8ju8SRwQqDoEFKJzbRsxiuAXQ3PBcJBXw1Qot9jz68TkqjiiNu/Testdatei.vrphoto?o=AtenENR8OcvlNq6JMa331mr-8gCreXxwcfgQ26B5gFKo&v=1&x=3&a=BclucinSeKmFAy2GJg&e=1413787013&k=OXDCcLTETbvUcOKdJ-vTdQ&r=567CC38A-FD1B-4DE6-B11B-4166A5669E1B-1&z=https%3A%2F%2Fp03-content.icloud.com%3A443&s=lO5SolOouS9qhYz1oIxKDoGtMpo&hs=ovfPXj3b9XXz9lWKChBmyNq_cug 
+1
source

All Articles