Skip to content

Commit

Permalink
Update examples (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-db authored May 30, 2023
1 parent 44dd638 commit 94b4589
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ To run the examples in your development environment:
1. Clone this repo
2. Run `npm install` and `npm run build`
3. Start the development server with `node server.js`.
4. Point your browser to <http://0.0.0.0:8080/>
4. Point your browser to <http://localhost:8080/>

# Dropbox TypeScript SDK Examples

Expand Down
5 changes: 3 additions & 2 deletions examples/javascript/PKCE-backend/code_flow_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const port = 3000;

const config = {
fetch,
clientId: [clientId],
clientId: '42zjexze6mfpf7x',
};

const { Dropbox } = require('dropbox'); // eslint-disable-line import/no-unresolved
Expand Down Expand Up @@ -45,8 +45,9 @@ app.get('/auth', (req, res) => { // eslint-disable-line no-unused-vars
});
})
.catch((error) => {
console.log(error);
console.error(error);
});
res.end();
});

app.listen(port);
2 changes: 1 addition & 1 deletion examples/javascript/auth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h2 class="code">
renderItems(response.result.entries);
})
.catch(function(error) {
console.error(error);
console.error(error.error || error);
});
} else {
showPageSection('pre-auth-section');
Expand Down
2 changes: 1 addition & 1 deletion examples/javascript/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2 class="code">
displayFiles(response.result.entries);
})
.catch(function(error) {
console.error(error);
console.error(error.error || error);
});
}

Expand Down
8 changes: 4 additions & 4 deletions examples/javascript/download/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ <h2 class="code">
var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN });
dbx.sharingGetSharedLinkFile({url: SHARED_LINK})
.then(function(data) {
var downloadUrl = URL.createObjectURL(data.fileBlob);
var downloadUrl = URL.createObjectURL(data.result.fileBlob);
var downloadButton = document.createElement('a');
downloadButton.setAttribute('href', downloadUrl);
downloadButton.setAttribute('download', data.name);
downloadButton.setAttribute('download', data.result.name);
downloadButton.setAttribute('class', 'button');
downloadButton.innerText = 'Download: ' + data.name;
downloadButton.innerText = 'Download: ' + data.result.name;
document.getElementById('results').appendChild(downloadButton);
})
.catch(function(error) {
console.error(error);
console.error(error.error || error);
});
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/javascript/node/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ prompt.get({
const dbx = new Dropbox({ accessToken: result.accessToken });
dbx.sharingGetSharedLinkFile({ url: result.sharedLink })
.then((data) => {
fs.writeFile(data.name, data.fileBinary, 'binary', (err) => {
fs.writeFile(data.result.name, data.result.fileBinary, 'binary', (err) => {
if (err) { throw err; }
console.log(`File: ${data.name} saved.`);
console.log(`File: ${data.result.name} saved.`);
});
})
.catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/javascript/pkce-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h2 class="code">
renderItems(response.result.entries);
})
.catch((error) => {
console.error(error)
console.error(error.error || error);
});
} else {
showPageSection('pre-auth-section');
Expand Down
7 changes: 4 additions & 3 deletions examples/javascript/simple-backend/code_flow_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const port = 3000;

const config = {
fetch,
clientId: 'jg8wc1hfkvel6ql',
clientSecret: 'f0i5w4e6mlbbme5',
clientId: 'APP_KEY_HERE',
clientSecret: 'APP_SECRET_HERE',
};

const { Dropbox } = require('dropbox'); // eslint-disable-line import/no-unresolved
Expand Down Expand Up @@ -45,8 +45,9 @@ app.get('/auth', (req, res) => { // eslint-disable-line no-unused-vars
});
})
.catch((error) => {
console.log(error);
console.error(error);
});
res.end();
});

app.listen(port);
10 changes: 5 additions & 5 deletions examples/javascript/team-as-user/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ <h2 class="code">

<!-- Example description and UI -->
<section class="container main">
<p>This example shows how to use the Dropbox class and the <code>Dropbox.actAsUser()</code> [<a href="http://dropbox.github.io/dropbox-sdk-js/Dropbox.html#actAsUser">docs</a>] method, to retreive a Dropbox class that is acting as a specific user on the team.</p>
<p>This example shows how to use the Dropbox class and the <code>selectUser</code> [<a href="https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#Dropbox__anchor">docs</a>] parameter, to retreive a Dropbox class that is acting as a specific user on the team.</p>

<form onSubmit="return listFiles()">
<input type="text" id="access-token" placeholder="Access token" />
<input type="text" id="user-id" placeholder="User id" />
<input type="text" id="member-id" placeholder="Member ID" />
<button type="submit">Submit</button>
</form>

Expand All @@ -46,15 +46,15 @@ <h2 class="code">
<script>
function listFiles() {
var ACCESS_TOKEN = document.getElementById('access-token').value;
var USER_ID = document.getElementById('user-id').value;
var dbxTeam = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN , assumeUser: USER_ID});
var MEMBER_ID = document.getElementById('member-id').value;
var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN , selectUser: MEMBER_ID});
dbx.filesListFolder({path: ''})
.then(function(response) {
displayFiles(response.result.entries);
console.log(response);
})
.catch(function(error) {
console.error(error);
console.error(error.error || error);
});
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/javascript/team/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2 class="code">
displayDevices(response.result.devices)
})
.catch(function (error) {
console.error(error);
console.error(error.error || error);
});
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions examples/javascript/upload/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 id="results"></h2>
var file = fileInput.files[0];


if (file.size < UPLOAD_FILE_SIZE_LIMIT) { // File is smaller than 150 Mb - use filesUpload API
if (file.size < UPLOAD_FILE_SIZE_LIMIT) { // File is smaller than 150 MB - use filesUpload API
dbx.filesUpload({path: '/' + file.name, contents: file})
.then(function(response) {
var results = document.getElementById('results');
Expand All @@ -60,12 +60,12 @@ <h2 id="results"></h2>
console.log(response);
})
.catch(function(error) {
console.error(error);
console.error(error.error || error);
});
} else { // File is bigger than 150 Mb - use filesUploadSession* API
const maxBlob = 8 * 1000 * 1000; // 8Mb - Dropbox JavaScript API suggested max file / chunk size
} else { // File is bigger than 150 MB - use filesUploadSession* API
const maxBlob = 12 * 1024 * 1024; // 8MB - Dropbox JavaScript API suggested chunk size

var workItems = [];
var workItems = [];

var offset = 0;

Expand All @@ -80,7 +80,7 @@ <h2 id="results"></h2>
// Starting multipart upload of file
return acc.then(function() {
return dbx.filesUploadSessionStart({ close: false, contents: blob})
.then(response => response.session_id)
.then(response => response.result.session_id)
});
} else if (idx < items.length-1) {
// Append part to the upload session
Expand Down
4 changes: 2 additions & 2 deletions examples/typescript/download/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ prompt.get({
// Note: The fileBinary field is not part of the Dropbox SDK
// specification, so it is not included in the TypeScript type.
// It is injected by the SDK.
fs.writeFile(data.name, (<any> data).fileBinary, { encoding: 'binary' }, (err) => {
fs.writeFile(data.result.name, (<any> data).result.fileBinary, { encoding: 'binary' }, (err) => {
if (err) { throw err; }
console.log(`File: ${data.name} saved.`);
console.log(`File: ${data.result.name} saved.`);
});
})
.catch((err: Error<sharing.GetSharedLinkFileError>) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/typescript/download/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 94b4589

Please sign in to comment.