Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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.
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.
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.
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.
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.
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.
Hi there!
If you need more help you can view your support options (expected response time for a 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!