Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I am developing an ap using Flutter framework. My app involves me using dropbox api to upload folders from my phone to my dropbox account. The problem I am having now is an error with content-type in the API. What content-type can I use for dropbox in my flutter app?
Thanks
[Cross-linking for reference: https://stackoverflow.com/questions/57692602/flutter-http-content-type ]
For reference, can you share the relevant code, and the error you're getting?
When uploading to Dropbox via the API, e.g., using the /2/files/upload, the Dropbox API expects the file data in the request body, with a "Content-Type" of "application/octet-stream".
Here's the code
String token = API().token; var map = new Map<String, String>(); map["Dropbox-API-Arg"] = '{"path": "/EasyBay/Project1/image.txt"}'; Map<String, String> requestHeaders = { 'Content-type': 'application/octet-stream', 'User-Agent': 'api-explorer-client', // 'Dropbox-API-Arg': '{"path": "/EasyBay/Project1/image.txt"}', 'Authorization': 'Bearer' + token }; var response = await http.post(new API().upload_link, body: map, headers: requestHeaders); print(response.statusCode); return parseChat(response.body);
While this is the error
Thanks! It looks like the error message is:
"Bad state: Cannot set the body fields of a Request with content-type "application/octet-stream"."
That's not an error message from the Dropbox API itself. It appears to be an error message from the HTTP client you're using. It looks like the problem is that you're attempting to set the "body" parameter to be a Map value, which isn't supported in this case.
When uploading to Dropbox via an upload API endpoint, the request body should contain the file data. In your code you're attempting to set it to a Map contain the API parameters, which wouldn't work anyway.
You should update your code to send the file data in the request body, and set the API parameters for the API call in a "Dropbox-API-Arg" request header, which would be in the "requestHeaders" variable you currently have (like the commented out line).
Thanks. I will check it out
Hi there!
If you need more help you can view your support options (expected response time for a 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!