cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Umlauts in file names

Umlauts in file names

Klaus A.
Helpful | Level 5

Hi, I am using the v2 API for http. What I found is that if a file or folder name contains a special character, like a German Umlaut like ä, I get a 400 error on upload and download. Is this a bug? 

During download the response text is "Error in call to API function "files/download": HTTP header "Dropbox-API-Arg": could not decode input as JSON".

During upload the response text is "Error in call to API function "files/upload": HTTP header "Dropbox-API-Arg": could not decode input as JSON".

 

Seems like there's a bug in the JSON.parse() function on DropBox's side. The same JSON stringified text with an umlaut in the file name will parse just fine in the browsers I tested.

 

 

11 Replies 11

Greg-DB
Dropbox Staff

For these calls with the parameters in the header, you need to escape these characters. That is, when you use the “Dropbox-API-Arg” header, you need to make it “HTTP header safe”. This means using JSON-style “\uXXXX” escape codes for the character 0x7F and all non-ASCII characters.

 

Some, but not all, languages/libraries do this for you. For example, for JavaScript, to do this yourself you could do something like this:

var charsToEncode = /[\u007f-\uffff]/g;
function http_header_safe_json(v) {
return JSON.stringify(v).replace(charsToEncode,
function(c) {
return '\\u'+('000'+c.charCodeAt(0).toString(16)).slice(-4);
}
);
}

and then:

"Dropbox-API-Arg": http_header_safe_json(arg)

 

Klaus A.
Helpful | Level 5

Thanks Greg, that worked. And thanks for answering on a sunday too.

 

developer_net
Explorer | Level 4
Hi Klaus
I have the same problem with a .net application.
I tried differend solutions to change the "Ä" in my path, but it will not work.
Do you have a tip for a dropbox newcommer? How have you solved the exception
My (notworking) path with umlaut looks like this:
{"path": "/Bild mit Umlaut/Ä Wasser.jpg","format": "jpeg","size": "w128h128"}
Best regards Horst

Klaus A.
Helpful | Level 5

I got a solution from Dropbox support that works. You need to escape all non-ASCII characters 'JSON' style. Which means all characters with character codes > 0x7F have to be replaced by a 4-digit hex code (it's hex unicode), preceeded by '\u'. For example Ä would be replaced with \u00c4 in the file name string. 

Replacing parts of a string is very straightforward in Javascript, but a little more involved in a language like C.

 

Greg-DB
Dropbox Staff

For example, in C#, using Json.NET/JsonTextWriter, that would look like:

 

 

var sb = new StringBuilder(); 
var textWriter = new JsonTextWriter(new StringWriter(sb)); 
textWriter.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii; 

// Write things to text writer 
textWriter.WriteStartArray(); 
textWriter.WriteValue("Hello");

... 

var result = sb.toString().Replace("\x7f", "\\u007f");

 

Or, using Json.NET/JsonConvert:

 

var serializerSettings = new JsonSerializerSettings(); 
serializerSettings.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii; 

var result = JsonConvert.SerializeObject(..., serializerSettings); 
result = result.Replace("\x7f", "\\u007f");

developer_net
Explorer | Level 4
Thank you Klaus!
Upgrading vom Json.net 4.5 to 10 and using the StringEscapeHandling.EscapeNonAscii solves my problem 😉
Best regards, Horst

mi2
New member | Level 2

My file path is saved in a c++ std::string. Can you please provide code to do that character skipping in C++? Thanks.

 

Greg-DB
Dropbox Staff

@mi2 I unfortunately don't have a sample for C++. Please refer to my C# samples above and translate them for your platform.

Abhishek3881000
New member | Level 2

Is there any way to do this in java?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Abhishek3881000 New member | Level 2
  • User avatar
    mi2 New member | Level 2
What do Dropbox user levels mean?