-
Notifications
You must be signed in to change notification settings - Fork 351
/
index.html
68 lines (63 loc) · 2.86 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html>
<head>
<title>Dropbox JavaScript SDK</title>
<link rel="stylesheet" href="/styles.css">
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@7/dist/polyfill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
<script src="/__build__/Dropbox-sdk.min.js"></script>
</head>
<body>
<!-- Example layout boilerplate -->
<header class="page-header">
<div class="container">
<nav>
<a href="/">
<h1>
<img src="https://cfl.dropboxstatic.com/static/images/brand/logotype_white-vflRG5Zd8.svg" class="logo" />
JavaScript SDK Examples
</h1>
</a>
<a href="https://github.com/dropbox/dropbox-sdk-js/tree/main/examples/javascript" class="view-source">View Source</a>
</nav>
<h2 class="code">
<a href="/">examples</a> / download file
</h2>
</div>
</header>
<!-- Example description and UI -->
<section class="container main">
<p>This example shows how to use the <code>Dropbox.sharingGetSharedLinkFile()</code> [<a href="http://dropbox.github.io/dropbox-sdk-js/Dropbox.html#sharingGetSharedLinkFile">docs</a>] method to download the file for the given shared link.</p>
<form onSubmit="return downloadFile()">
<input type="text" id="access-token" placeholder="Access token" />
<input type="text" id="shared-link" placeholder="Dropbox shared link to a file" />
<button type="submit">Submit</button>
</form>
<!-- The download button is added here -->
<div id="results" style="margin-top: 30px"></div>
<p class="info">To obtain an access token for quick testing, you can go to <a href="https://dropbox.github.io/dropbox-api-v2-explorer/#files_list_folder" target="_blank">API Explorer</a> click the "Get Token" button on the top right, copy the token it creates and then paste it here.</p>
</section>
<!-- Scripts to run example -->
<script>
function downloadFile() {
var ACCESS_TOKEN = document.getElementById('access-token').value;
var SHARED_LINK = document.getElementById('shared-link').value;
var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN });
dbx.sharingGetSharedLinkFile({url: SHARED_LINK})
.then(function(data) {
var downloadUrl = URL.createObjectURL(data.result.fileBlob);
var downloadButton = document.createElement('a');
downloadButton.setAttribute('href', downloadUrl);
downloadButton.setAttribute('download', data.result.name);
downloadButton.setAttribute('class', 'button');
downloadButton.innerText = 'Download: ' + data.result.name;
document.getElementById('results').appendChild(downloadButton);
})
.catch(function(error) {
console.error(error.error || error);
});
return false;
}
</script>
</body>
</html>