We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
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 ...
ingconti
Helpful | Level 5
this is my Swift code:
case .Upload:
var optionsStr = "{\"path\": \"PATH_PLACEHOLDER\",\"mode\": \"add\",\"autorename\": AUTORENAME_PLACEHOLDER, \"mute\": false,\"strict_conflict\": false}"
optionsStr = optionsStr.replacingOccurrences(of: "PATH_PLACEHOLDER", with: remotePath!)
let autoRename = autoRenameOnServer ? "true" : "false"
optionsStr = optionsStr.replacingOccurrences(of: "AUTORENAME_PLACEHOLDER", with: autoRename)
#if DEBUG
print("header: ", optionsStr, "\n")
#endif
request.setValue(optionsStr, forHTTPHeaderField: "Dropbox-API-Arg")
request.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
And I send it AS other cases (for example LIST)
the above code is for uploading.
As said, it worked a couple of weeks ago and for more than 2 years.
SO the unique reason is Siem Apis is changed OR other inner things, but NO decent details.,
ingconti
3 years agoHelpful | Level 5
to be cleat: after this code we issued the USUAL, beloved, apple-endorsed code:
let session = URLSession.shared
let task = session.dataTask(with: request as URLRequest, completionHandler: {data, response, error -> Void in
......
- ingconti3 years agoHelpful | Level 5
would be useful alo if Your programmers can send back some simular code (shell scripts..) I can run via MAC/Unix/Linux bash to get the same result uploading a file.
- Greg-DB3 years agoDropbox 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.
- ingconti3 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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 12 months 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!