You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
sr_c
2 years agoExplorer | Level 3
save_url throws error "request body: could not decode input as JSON"
Hi
I am trying to upload files (pictures with .jpg extension) to my dropbox account (to a specific app folder). I am using Airtable scripting (Javascript) extension to upload files from Airtable (...
- 2 years ago
sr_c wrote:...},data: filedata}...sr_c, When you are preparing a request body with appropriate data, you have to set those data. What actually is going on here? 🤔 You have already prepared request body (that you named as 'filedata' - incorrect name and probably confusing)! In this context instead of setting 'data', you have to set 'body'. 😉 Be more careful!
Hope this helps.
sr_c
Explorer | Level 3
Hi
Based on the suggestion to use JSON.stringify, I tried to implement below solution but error remains same. Not sure whether this is the right way to implement the suggestion. Changes highlighted in blue
------------------------------------------------------------------------------------------
let appToken = "<<App Token>>"
let fileobj = {
"path":"/myairsri/best_peacock.jpg",
"url":urlval
}
let filedata = JSON.stringify(fileobj)
// set up the post options
let postOptions = {
method: "POST",
headers: {
"Authorization" : "Bearer " + appToken,
"Content-Type" : "application/json"
},
data: filedata
}
Please let me know your suggestions
Thanks
Здравко
2 years agoLegendary | Level 20
sr_c wrote:...},data: filedata}...
sr_c, When you are preparing a request body with appropriate data, you have to set those data. What actually is going on here? 🤔 You have already prepared request body (that you named as 'filedata' - incorrect name and probably confusing)! In this context instead of setting 'data', you have to set 'body'. 😉 Be more careful!
Hope this helps.
- Greg-DB2 years agoDropbox Staff
sr_c I see you're using fetch to perform the call, so make sure you're using the right options to construct the call as needed. As Здравко said, fetch expects a parameter named 'body' to set the request body, not 'data'.
- sr_c2 years agoExplorer | Level 3
Hello Здравко
Your suggestion worked like a charm and I am able to upload files. Thanks a lot
But I am wondering why Dropbox API documentation is showing 'data' instead of 'body' in the 'Example' (screen shot attached below)
- Здравко2 years agoLegendary | Level 20
The example on the page, you posted, uses 'curl' shell command. That's the way (one of all actually) body to be represented. You're working with 'fetch' command in javascript, not shell! Just different things! 😉 Pay attention on the proper documentation. None of these parameters (how they are named) can be seen by Dropbox server - just properly formated request is expected.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,884 PostsLatest Activity: 3 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!