Hello,
Downloading from Dropbox fail on the android. It succeed using same code on the ios .
The following is the response from server when error occured.
07-15 22:41:06.535 I/Corona (13900): {responseHeaders = {Connection = “keep-alive”, Content-Type = “text/plain; charset=utf-8”, X-Dropbox-Request-Id = “1c430a91ce4c931564879c5ba34f1858”, X-Android-Response-Source = “NETWORK 400”, Date = “Fri, 15 Jul 2016 14:41:03 GMT”, X-Android-Sent-Millis = “1468593665314”, Transfer-Encoding = “chunked”, X-Android-Received-Millis = “1468593666521”, X-Robots-Tag = “noindex, nofollow, noimageindex”, X-Android-Selected-Transport = “http/1.1”, HTTP-STATUS-LINE = “HTTP/1.1 400 Bad Request”, Server = “nginx”, }, responseType = “text”, phase = “ended”, bytesEstimated = -1, response = “Error in call to API function “files/download”: You provided a non-empty HTTP “Content-Type” header (“application/x-www-form-urlencoded”). This API function requires that the header be missing or empty.”, name = “networkRequest”, bytesTransferred = 203, status = 400, url = “https://content.dropboxapi.com/2/files/download”, isError = false, requestId = false, }
the following is when succeeded.
2016-07-15 22:25:24.603 nibblebb[17329:4609872] {responseHeaders = {Connection = “keep-alive”, Content-Type = “application/octet-stream”, X-Dropbox-Request-Id = “789243a8206a1612e495b86bcb390afe”, Date = “Fri, 15 Jul 2016 14:25:17 GMT”, dropbox-api-result = “{“name”: “nibblebb.zip”, “path_lower”: “/nibblebb.zip”, “path_display”: “/nibblebb.zip”, “id”: “id:XxQSUykzBvAAAAAAAAAAAQ”, “client_modified”: “2016-07-15T13:52:15Z”, “server_modified”: “2016-07-15T13:52:15Z”, “rev”: “a645e1dfe2”, “size”: 167384}”, original-content-length = “167384”, X-Robots-Tag = “noindex, nofollow, noimageindex”, Content-Length = “167384”, Cache-Control = “no-cache”, X-Server-Response-Time = “165”, Accept-Ranges = “bytes”, Pragma = “no-cache”, Etag = "W/“a645e1dfe2"”, Server = “nginx”, }, responseType = “binary”, phase = “ended”, bytesEstimated = 167384, response = {fullPath = “/var/mobile/Containers/Data/Application/49BCB3E8-F1E1-4876-879A-91C29DA703F8/Documents/nibblebb.zip”, filename = “nibblebb.zip”, baseDirectory = userdata: 0x5ef6f1, }, name = “networkRequest”, bytesTransferred = 167384, status = 200, url = “https://content.dropboxapi.com/2/files/download”, isError = false, requestId = userdata: 0x19dbc9c4, }
The following is the source code.
function M.downloadFile(filename, cb) if nil == M.accessToken then return end callback = cb local url = "https://content.dropboxapi.com/2/files/download" local params = {headers={}} params.headers["Authorization"] = "Bearer "..M.accessToken params.headers["Dropbox-API-Arg"] = "{\"path\": \"/"..filename.."\"}" network.download( url, "POST", function(event) print(dumpdata:dump(event, true)) if event.isError then print("network error:", event.status, event.response) if nil ~= callback then callback(M.err\_network) end else print("dropbox response:", event.status, dumpdata:dump(event.response, true)) if nil ~= callback then if 200 == event.status then callback(M.err\_none) elseif 401 == event.status then callback(M.err\_atexpired) else callback(M.err\_downloadfile) end end end end, params, filename) end
If I set bodyType=“binary”, Content-Type is not set automatically.
But if I set bodyType and not set body, eventually Content-Type will be set automatically.
If I set body, ‘body should be empty’ error occured.
Is there a way to avoid this problem?