You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

PerOstergren's avatar
PerOstergren
Explorer | Level 4
4 years ago

SwiftyDropbox: copy files from shared folder link to App folder, or download to local Documents

Very new to the platform, all help appreciated.

 

My aim is to populate my iOS app with some files that originally resides in a shared Dropbox folder, either by downloading them to the local device, or somehow copy the content of the folder to the app's Dropbox folder from where I can download copies to the app for offline access. 

 

Having successfully listed the contents of shared folders in my app, I'm finding no example documentation of how to either copy said files from the shared directory to my Dropbox app folder, or how to download them to my local device.

 

I have implemented the listFolder using the sharedLink URL and got it working listing all files and get the metadata associated with them, but both methods that I assume is responsible for fetching the files (copyV2, sharing.getSharedLinkFile) seems to be using a path to the file(s) rather than an URL like listFolder. I therefore haven't been able to implement a method that either downloads, or copies the content of the folder as I don´t know how to supply a 'path' when all I have is a URL or sharedLink.

 

Having searched the web with most, if not all possible questions relating to this, I can't find any answer or example on how to resolve my problem.

 

Thankful for any information or example code that can point me in the right direction.

  • To download a file from a shared link for a folder to the local device, you should use listFolder/listFolderContinue, to list the contents of the linked folder, and then getSharedLinkFile to download any needed file(s). When calling getSharedLinkFile, the 'path' should be the path of the file you want to download, relative to the linked folder, and the 'url' should be the shared link for the folder. You can determine the relative path from the metadata returned by listFolder/listFolderContinue, from the Metadata.name for the needed file(s). For example, if it's a file named "file.ext" in the linked folder, the path would be "/file.ext". Or, if it's nested in a subfolder named "subfolder" in the linked folder, the path would be "/subfolder/file.ext".

     

    Alternatively, you can save a file from a shared link for a folder directly to a connected Dropbox account by using getSharedLinkMetadata and saveUrl. You would call getSharedLinkMetadata with the 'url' and 'path' value (built the same was as above), to get the resulting SharedLinkMetadata.url for the specific file in the linked folder that you want. Then you would pass that to saveUrl as 'url' to save that file to the connected account.

     

    However, note that unfortunately there is currently a bug that will prevent getSharedLinkFile and getSharedLinkMetadata from working if your app has the "app folder" access type. That's currently open with engineering, but I don't have a timeline for a fix.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    To download a file from a shared link for a folder to the local device, you should use listFolder/listFolderContinue, to list the contents of the linked folder, and then getSharedLinkFile to download any needed file(s). When calling getSharedLinkFile, the 'path' should be the path of the file you want to download, relative to the linked folder, and the 'url' should be the shared link for the folder. You can determine the relative path from the metadata returned by listFolder/listFolderContinue, from the Metadata.name for the needed file(s). For example, if it's a file named "file.ext" in the linked folder, the path would be "/file.ext". Or, if it's nested in a subfolder named "subfolder" in the linked folder, the path would be "/subfolder/file.ext".

     

    Alternatively, you can save a file from a shared link for a folder directly to a connected Dropbox account by using getSharedLinkMetadata and saveUrl. You would call getSharedLinkMetadata with the 'url' and 'path' value (built the same was as above), to get the resulting SharedLinkMetadata.url for the specific file in the linked folder that you want. Then you would pass that to saveUrl as 'url' to save that file to the connected account.

     

    However, note that unfortunately there is currently a bug that will prevent getSharedLinkFile and getSharedLinkMetadata from working if your app has the "app folder" access type. That's currently open with engineering, but I don't have a timeline for a fix.

    • Greg-DB's avatar
      Greg-DB
      Icon for Dropbox Staff rankDropbox Staff

      Update: the /2/sharing/get_shared_link_metadata and /2/sharing/get_shared_link_file endpoints (and corresponding methods in the SDKs) should now work when using an access token for an app with the app folder access type.

    • PerOstergren's avatar
      PerOstergren
      Explorer | Level 4
      Thank you for the push in the right direction, Greg-Db! Had created the App folder only alternative, have made a new app and now got it working. Will the savurl method make me able to check individual files for changes in revision number? From what I’m able to read, it’s only files that resides in one’s own DB folder that can have rev listed in its metadata, not files that are shared via link?

      Again, thanks!
      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        The saveUrl method just allows you to save a file from a URL to the connected Dropbox account. That URL can be a Dropbox shared link, and in that case it will just save the latest version of the linked file; there isn't a way to specify a different revision.

         

        As for the metadata, you can only get the list of revisions for files in the connected account (via listRevisions), not for files from shared links. You can use getSharedLinkMetadata to get the metadata for the linked file, which includes the current 'rev' value, but not previous values.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,886 PostsLatest Activity: 2 hours ago
326 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!