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
ingconti
3 years agoHelpful | Level 5
Re: Error in call to API function "files/upload": HTTP header "Dropbox-API-Arg":
good you are available
Said so, pls let me know How to fix it.
to recap:
a) my ap is written in swift, NO other components (neither official dropbox library, too big and too messy)
b) it did ...
Greg-DB
Dropbox Staff
For reference, the documentation for /2/files/upload includes a basic example of how you might call curl in a shell to perform an upload. The API Explorer can also be useful for prototyping and testing calls. (Click "Show Code" to see an example of what the code would look like.)
Anyway, the /2/files/upload endpoint is a "Content-upload" style endpoint, so it takes the parameters as JSON in the "Dropbox-API-Arg" header. In your code I see you're building that JSON by replacing portions of a pre-existing string. I recommend using actual JSON writing functionality (for instance, provided by your platform or a library) to build that instead, as that should be less error prone.
For instance, it's possible I see you're inputting the remotePath value, and it's possible that value has changed to something that is causing your code to produce invalid JSON, such as to include some character that needs to be escaped.
When putting these values in the header, make sure you're encoding them properly. We have a documentation page here that explains what needs to be escaped, including an example written on Swift at the bottom. Check that out and make sure you're building and encoding your JSON string properly as shown there.
ingconti
3 years agoHelpful | Level 5
sorry, BUT I DID read all docs, so ls don't say to read docs. Pls respond Wirth TECH answers.
From Your answer I clearly understand you dint know swift, you assumption about string function re COMPLETELY wrong.
in detail I am USING "using actual JSON writing functionality (for instance, provided by your platform or a library)": as every serious programmers knows
JSON is bases ion strings.
"For instance, it's possible I see you're inputting the remotePath value, and it's possible that value has changed to something that is causing your code to produce invalid JSON, such as to include some character that needs to be escaped." is completely technically wrong.
"remotePath" is a let (const in C/C++) so NOT possibile.
About ecaping as said above I did escaped reading your docs. I did validate it and it si correct:
{"path": "/OUT/aaaaa_000.jpg","mode": "add","autorename": true, "mute": false,"strict_conflict": false}
I will giver a try to escaping, BUT as said, it worked for months in production.
- Greg-DB3 years agoDropbox Staff
I was referring to using something like JSONSerialization.data to build the JSON string from a dictionary for you, like in our example.
Regarding the remotePath value, while that may be a constant in your code (though you did not share where that is defined), is it possible you've changed what you assign to it in your code at some point?
I see in your latest comment that you included an example of the JSON string you're building, showing the path as "/OUT/aaaaa_000.jpg". Looking at that carefully, I see that the "_" character is not actually an ASCII underscore, but rather a Unicode character named "Fullwidth Low Line" (U+FF3F). That being the case, you will need to apply the encoding as documented, otherwise you'll run in to an error.
I just tried this myself and confirmed that running your code as shown with that character does cause a failure, but using the documented code to serialize and encode the parameters does work.
- ingconti3 years agoHelpful | Level 5
1) You wrote: "I was referring to using something like JSONSerialization.data to build the JSON string from a dictionary for you, like in our example.'
I Did write and teste din other environments and it worked, I have extensive Unit testing about.
2) d "Fullwidth Low Line" (U+FF3F).
3 consideration:
2a) it WORKED for an year, so what changed?
2b) THIS should be the 1st response
3b) why giving back such message should be a problem for backend?
I wil try Your encoding function, I will re-post.
- ingconti3 years agoHelpful | Level 5
I got from your example :
{"field":"some_\u00fc\u00f1\u00eec\u00f8d\u00e9_and_\u007f"}
if is correct, pls fix code that does NOT compile in swift any more, as JSONSerialization.data can throw:
let args = ["field": "some_üñîcødé_and_\u{7F}"]
if let jsonData = try? JSONSerialization.data(withJSONObject: args){
let encodedArgs = asciiEscape(utf8Decode(jsonData))
print(encodedArgs)
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,910 PostsLatest Activity: 3 days 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!