Chooser
Using the Chooser
The Chooser is the fastest way to get files from Dropbox into your web app. It’s a small JavaScript component that enables your app to get files from Dropbox without having to worry about the complexities of implementing a file browser, authentication, or managing uploads and storage.
This tutorial will guide you through everything you need to do to add the Chooser to your app and customize it to suit your use cases.
Demo
Click the button below to see the Chooser in action. This demo triggers a Chooser, which lets you choose a file from your Dropbox. Once a file is selected, the link is returned to the host website.
Setup
The first step in adding the Chooser to your app is to create an app. Using the Chooser doesn’t require production approval, so you can publish your integration to your users as soon as you’re ready.
When you create a Chooser app for the web, you’ll need to provide the domain names where your app is hosted. This lets us stop other websites from trying to impersonate your app.
Once you’ve created a new app, add the following JavaScript snippet to your HTML.
Replace YOUR_APP_KEY with the app key from your app’s page in the App Console.
Triggering the Chooser from JavaScript
There are two ways to trigger the Chooser on your website. To create the nice styled button you see in the demo above, you can use the following JavaScript:
If you prefer to design a custom button instead, you can trigger the Chooser directly from JavaScript using the following method:
Note that the Chooser opens in a pop-up window, so you should only call this function from within a user-triggered event handler such as a tap or click event. Otherwise, the pop-up will likely be blocked by the browser.
Security note: If you provide a custom windowName in the options, avoid using predictable or hardcoded values. Predictable window names can be pre-registered by attackers to hijack the browsing context. If you don’t provide a windowName, a cryptographically random one will be generated automatically.
Both methods take a single options parameter with the following fields:
Handling the response
The files parameter in the above success callback function will be an array of file objects, each containing info about the selected file. If multiselect is false, the array will contain a single item. Each file object includes the following fields:
The thumbnail link contains query string parameters that specify how the thumbnail is generated. By modifying these parameters, you can construct URLs for other sizes and modes of thumbnails:
- bounding_box Bounding box size for the thumbnail which must be one of the following values:
75(default),256,800,1280,2048. - mode One of the following resize modes:
- fit default Shrink the original image maintaining the original aspect ratio until the entire image fits inside the bounding box.
- crop Shrink the original image until its width or height fits in bounding box, then crop anything outside the bounding box.
- fit_one_and_overflow Shrink the original image until its width or height fits into the bounding box but do not crop the left overs. The returned image will be larger than the bounding box. This is useful for situations where you need to use a square thumbnail but also want to use that image as a placeholder while you load a higher resolution version in the background.
Note, thumbnail links are temporary; links will expire after 4 hours.
Link types
The Chooser can be configured to return one of two link types.
- preview links are the default type of link returned by the Chooser. Preview links point to a human-friendly preview page of a file and are great for sharing. You can read more about links to Dropbox files in our Help Center. Note that users may disable this link at a later point if they choose.
- direct links point directly to the contents of the file and are useful for downloading the file itself. Unlike preview links, however, they will expire after four hours, so make sure to download the contents of the file immediately after the file is chosen. Direct links also support CORS, which allows you to read the file information directly in the browser using client-side JavaScript. These URLs should not be used to display content directly in the browser.
File types
In addition to individual file extensions, the extensions parameter in JavaScript allows the following file types: images, audio, video, documents, and text. Each file type corresponds to a list of individual file extensions, as defined below.
images
bmpcr2gificoithmbjpegjpgnefpngrawsvgtiftiffwbmpwebp
audio
aacaifaifcaiffauflacm4amidmp3m4bm4pm4rogaoggopusraramspxwavwm
video
3gp3gpp3gpp23g2asfavidvdviflvm2tmp4m4vmkvmovmpegmpgmtsogvogxrmrmvbtsvobwebmwm
documents
csvdocdochtmldocmdocxdocxmldotdothtmldotmdotxepsfdfkeykeynotekthmppmptmpxmpdnmbtemplatenumbersodcodpodgodsodtpagespdfpdfxmlpotpothtmlpotmpotxppappamppsppsmppsxpptppthtmlpptmpptxpptxmlprnpspwzrtftabtemplatetsvtxtvdxvsdvssvstvsxvtxwpdwpsxdpxdfxlamxllxlrxlsxlsbxlsmxlsxxltmxltxxpswbkwpdwi
text
<no extension>applescriptasas3cccclispcoffeecppcscsscsvcxxdefdifferlfountainfthhpphtmhtmlhxxincinijavajsjsonlesslogluammmmarkdownmatmdmdownmkdnmustachemxmlpatchphpphtmlplplistpropertiespyrbsassscssshshtmlsqltabtaskpapertextexttmpltsvtxturlvbxhtmlxmlyamlyml
Supported browsers
Not all browsers support the Chooser. If a user’s browser doesn’t support the Chooser, we’ll gray out the button and show a warning message if you try to call Dropbox.choose(). You can check to see if the user’s browser is supported by calling Dropbox.isBrowserSupported().