Dropbox
Dropbox is a file hosting service that offers APIs for programmatic file access.
"Dropbox Apps" are the standard way to interact with the service. The "Dropbox App" section describes how this demo was configured.
The Dropbox API script is loaded in this page with
<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="4ysmnhy8wtm6k3w"></script>
The data-app-key
used in this demo is a "Development" key associated with the
localhost
and docs.sheetjs.com
domains. Dropbox API does not require
"Production" approval for the Chooser or Saver.
The live demos require a Dropbox account.
Reading Files
"Chooser" is a small library that lets users select a file from their account.
Live Demo
The button must have the following options:
multiselect: false
ensures only one file can be selectedfolderselect: false
limits selection to real fileslinkType: "direct"
ensures the link points to a raw file
When a file is selected, the success
callback will receive an array of files
(even if multiselect
is disabled). Each file object has a link
file which
corresponds to a temporary URL that can be fetched.
If the live demo shows a message
ReferenceError: Dropbox is not defined
please refresh the page. This is a known bug in the documentation generator.
Writing Files
The Dropbox API was not designed for writing files that are created in the web browser. The Data URI approach is a neat workaround but should not be used in production for larger files. It is better to create the files in the server using NodeJS and generate a proper URL for Dropbox to fetch.
"Saver" is a small library that lets users save files to their account.
Live Demo
The file must be written before the Save button is created. Unfortunately the
API does not accept data in the POST body, so the workaround is to create a data
URI by writing with the base64
type and prepending the URI metadata.
This demo seeds data by fetching a file and writing to HTML table. The generated table is scraped to create a new workbook that is written to XLS.
If the live demo shows a message
ReferenceError: Dropbox is not defined
please refresh the page. This is a known bug in the documentation generator.
Dropbox App
This demo requires a "Dropbox app":
0) Create a Dropbox app through the Developer tools. For this demo:
- "Choose an APU": "Scoped access"
- "Choose the type of access you need": "Full Dropbox"
- "Name": (enter any name) "SheetJS Docs"
The Dropbox API Terms and Conditions should be reviewed before acceptance.
1) Configure the Dropbox app in the Developer tools.
The following permissions should be selected in the "Permissions" tab
files.metadata.write
(View and edit information about your Dropbox files and folders)files.metadata.read
(View information about your Dropbox files and folders)files.content.write
(Edit content of your Dropbox files and folders)files.content.read
(View content of your Dropbox files and folders)
In the settings tab, under "Chooser / Saver / Embedder domains", the desired
public domains should be added. localhost
must also be added for development
use (it is not automatically enabled).