cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Re: Accented characters in file name

Accented characters in file name

anildbest83
Explorer | Level 3
Go to solution

I m using Dropbox V2 API  and when try to upload a file with name 'tête-à-tête' getting following error

 

Error in call to API function "files/upload_session/finish": HTTP header "Dropbox-API-Arg": could not decode input as JSON

 

Also if my folder name is 'tête-à-tête' then uploading any file inside it also goes to folder 't�te-�-t�te'.

 

In this case Accented character changed in header.

 

I m using .Net with C#

 

Please suggest.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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, 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");

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

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, 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");

anildbest83
Explorer | Level 3
Go to solution

Thanks @Greg-DB , it is working absolutely fine.

Need more support?