We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

wheel's avatar
wheel
Explorer | Level 4
7 years ago

Response headers

when i use dropbox api for uploading file.  the http header contain chinese, for example:

"Dropbox-API-Arg:{\"path\": \"/Test/中文.doc\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}".

it will response error message:

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

how should i do?

thanks.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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)
    • wheel's avatar
      wheel
      Explorer | Level 4

      Thanks for replying.

      I use dropbox api with winhttp and c.

      Now, i'm trying to encode chinese to unicode. For example:

      "工作.doc" -->  "\u5de5\u4f5c.doc" ,

      and the header is :

      Dropbox-API-Arg:{\"path\": \"/Test/\u5de5\u4f5c.doc\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}.

      But it also response error message:

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

      So, if i want to create the filename with chinese,  what format should i input to header? 

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        It looks like you're properly escaping the Unicode characters, but you have an extra period at the end of the string, making it invalid JSON. Remove that extra "." and try again.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 24 minutes ago
325 Following

If 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!