Kloudless Blog

Kloudless Unified APIs enable you to code once and integrate many

Photo by Samuel Zeller on Unsplash

“If we always helped one another, no one would need luck.”

It’s Monday, and that means we’re back with another post aimed at helping you overcome some of the most commonly asked questions about the APIs we work with here at Kloudless. Every Monday, we will aim to help answer some of the more repeated inquiries into the world’s most popular APIs. Today, we will be turning back to one of the industry’s top names when it comes to file storage: Dropbox.

Boasting more than 500 million users, DropBox has been a bona fide giant of the cloud-based file storage world since its release in 2008. DropBox became the first of the ‘folder sync’ storage applications to become a household name, having been originally conceived when one of its co-founders left his USB flash drive at home and was stuck with no way to access his necessary files for a college class. As a result, DropBox has become ubiquitous with users looking to manage their files and documents in the cloud, and heavily utilized by applications looking to provide their users with storage integrations.

Today, we will cover using the official Dropbox API Python SDK to download files locally. Initially, in the Dropbox API v1, the function get_file_and_metadata was how one could save a file for local download. Now, in the Dropbox API v2, that function has been removed. We found that many users across the internet were stuck looking for a fix now that the API has changed. Let’s discuss the API’s changes, and how you can reproduce the same functionality using Dropbox’s new Python SDK functions.

As mentioned above, the function get_file_and_metadata could be used to open or locally save a file from the API. Once you’ve imported the Python SDK library and given it your access token, you’ll be able to instantiate your dropbox object and access any of the library’s built-in methods. The code to grab the data would look something like this:

Now that the get_file_and _metadata function has been deprecated, there are two new functions that can replicate this functionality: files_download and files_download_to_file.

The first of these functions can give you read access to the file you wish to save, which can be used to save or overwrite another file with the data. The same code above would be retooled to look like this to get the same file:

However, to locally save the file on your computer, the latter of these two new functions is your best bet. It takes an additional parameter, but you can get the same functionality out of a single line of code, like so:

You will now have a local copy of file_name as long as your path points to the right place!

When incorporating Dropbox functionality into your application, keep in mind the benefits of adding as many file storage providers as possible. If your users are ingrained in another file storage provider like Box, Egnyte, or Google Drive, they may forego your application entirely in search of a competitor that provides the connection to their preferred service. Give your users the choices they need, while bolstering your own application’s functionality, with the use of a Unified API from Kloudless. You can offer your users dozens of file storage services in the same amount of code it would take to connect to a single API. On top of that, when response formats change or APIs update their access endpoints, a Unified API handles all the future maintenance necessary to keep functionality working. To learn more about the Kloudless Unified Storage API, please download our free guide to storage integration strategy today!


Share this article:

Let’s get started. Start building for free today.