New file upload link API

// By Kyle Anderson • Jan 31, 2019

The /get_temporary_upload_link API endpoint is now officially out of preview and available for production use. Developers can use this API call to get pre-signed upload URLs. 

Use Case for Temporary Upload Link

One of the most common actions a Dropbox integration will perform is to add new content.  

The /upload endpoint is used to push binary content to Dropbox. This is perfect for apps where the file is local to the machine connecting to Dropbox. However, for some types of client-server applications that integrate with Dropbox, this may be not optimal. For example, you may have a server-based application which manages all state and interaction with Dropbox and a mobile client that connects your server.  

In this scenario, uploading a new file to Dropbox via your app’s client with the upload endpoint would mean:

  1. Your client uploads the file to a temporary location on your server
  2. Your server uploads the file to Dropbox via the API

Enter pre-signed upload URLs. Using the /get_temporary_upload_link endpoint allows you to create a temporary, one-time use URL that can be sent to your client to upload a file. In this model:

  1. Your client asks your server for an upload URL
  2. Your server issues a call to Dropbox to get a URL, and returns that URL to your client
  3. The client posts the file to Dropbox directly to the returned URL

This method saves your server the storage, network traffic, and complexity of forwarding this content. It’s significantly faster end to end, while still allowing for OAuth credentials to be stored and secured centrally in your server infrastructure.

Example: Get Temporary Link Using DBX Python SDK

Here’s a python code snippet of how a server and client would use this URL.

Server

import dropbox
from dropbox.files import CommitInfo, WriteMode
# Receive a request from the client to get an upload URL
 
dbx = dropbox.Dropbox()
commit_info = CommitInfo(path=, mode=WriteMode.overwrite)
temp_link = dbx.files_get_temporary_upload_link(commit_info=commit_info)
print(temp_link.link)
 
# send upload url to client

Client

import requests
 
# Request an upload url from the server
 
data = open('', 'rb').read()
res = requests.post(url='', data=data, headers={'Content-Type': 'application/octet-stream'})
if (res.status_code == 200):
    print("Success. Content hash: "+res.json()['content-hash'])
elif (res.status_code == 409):
    print("Conflict. The link does not exist or is currently unavailable, the upload failed, or another error happened.")
elif (res.status_code == 410):
    print("Gone. The link is expired or already consumed.")
else:
    print("Other error")

If you have any questions about this or need help with anything else, you can always contact us here.

Build with Dropbox today at   www.dropbox.com/developers


// Copy link