We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
bbroscheit
11 months agoExplorer | Level 3
the files I upload with the api arrive corrupted
Hello, my name is Bernardo, I am wanting to implement the Dropbox API to a support system. I use the example that dropbox gives on github to upload files, in my code it works but when I enter the dro...
- 11 months ago
When uploading files to Dropbox via the Dropbox API, Dropbox will save whatever data you supply, so you'll need to make sure you're sending the exact correct data you want saved. In your code, I see you're calling the filesUpload method to upload the file. When doing so, you supply the data you want to upload in the 'contents' parameter.
In your code, you're sending the contents of the 'e' variable to that 'contents' parameter. You'll need to make sure that the data you're sending there is exactly and only the data for the file you're uploading. The 'e' variable in your code comes from the .map on your 'files' variable, but the code doesn't show where/how the 'files' variable is defined. You'll need to debug and update your code accordingly to make sure you pass in just the desired file data. (For instance, based on the other 'e.filename' usage of the 'e' variable, it looks like 'e' probably doesn't contain just the file data, but rather is an object containing some properties.)
bbroscheit
Explorer | Level 3
Thanks for the response, and sorry for my English but I'm using a translator.
In the end I was able to solve it yesterday, in the "saveInDropbox" function I am sending an object as a contents parameter to the filesUpload function but I had to treat it as a binary file, I added these lines to the code to the try statement
try {
const content = fs.readFileSync(e.path);
dbx
.filesUpload({ path: "/" + e.filename, contents: content })
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.error(error.error || error);
});
} catch (error) {
console.error("Error reading file:", error);
}
and it worked, Now the only thing left to solve is the issue that the token only lasts 3 hours, but I saw that there is a tutorial for that
Greg-DB
11 months agoDropbox Staff
Yes, Dropbox issues short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. Apps can still get long-term access by requesting "offline" access though, in which case the app receives a "refresh token" that can be used to retrieve new short-lived access tokens as needed, without further manual user intervention. Refresh tokens do not expire automatically and can be used repeatedly. You can find more information in the OAuth Guide and authorization documentation. There's a basic outline of processing this flow in this blog post which may serve as a useful example.
For examples of implementing this with the Dropbox JavaScript SDK, please refer to the examples included in the "examples" folder in the SDK. As long as you supply the necessary credentials, for instance, set the app key (a.k.a. client ID) and refresh token, like shown in this example for the JavaScript SDK, the SDK will actually handle refresh process for you automatically. (Note that the app secret is also required if the app does not use PKCE.) The SDK will automatically catch expired access token errors and call the API to get a new short-lived access token when needed.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 5 minutes agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!