cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Learn more about how Connie, a member of the Community, uses Dropbox here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

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

PerOstergren
Explorer | Level 4

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.

1 Accepted Solution

Accepted Solutions

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

Greg-DB
Dropboxer

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.

View solution in original post

5 Replies 5

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

Greg-DB
Dropboxer

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.

View solution in original post

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

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!

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

Greg-DB
Dropboxer

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.

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

PerOstergren
Explorer | Level 4

If I query with listFolder, get a response back and

print(response as Any)

, the folder content prints as a list of items as follows including rev, hash and id:

{
            ".tag" = file;
            "client_modified" = "2014-06-05T05:22:59Z";
            "content_hash" = 711560a047ed6607d41f328872246db9277d564aa400ee643c142871f8b48154;
            id = "id:n4ABlnhYTMcXXAAAAXXkg";
            "is_downloadable" = 1;
            name = "Photo 2014-06-04 19 33 53.jpg";
            "path_display" = "/Public/Photo 2014-06-04 19 33 53.jpg";
            "path_lower" = "/public/photo 2014-06-04 19 33 53.jpg";
            rev = 1e8a00562e0e;
            "server_modified" = "2014-06-05T05:23:59Z";
            size = 2010202;
        }

 

 

However, if I separarate the entries from the result 

for entry in result.entries { }

, I can't access the rev-value as it isnt listed anymore. Should I not use the response.entries method and instead try to parse the response on my own? Using getSharedLinkMetadata produces a result with more items, but no rev. The url used is for the shared folder, not a specific file.

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

Greg-DB
Dropboxer

To access FileMetadata.rev, you need to first cast Metadata to FileMetadata. There's an example of doing so here.

 

The getSharedLinkMetadata method will only return the metadata for the linked item. If you supply the link for the folder itself, you'll only get the metadata for the folder, which doesn't have a rev. You'd need to supply the link to the file to get the file's metadata.

Poll
Which Dropbox integrations are you using while working from home?
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?