network.download with empty 'Content-Type'

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?

Then why not set the bodyType to binary. It doesn’t hurt to use binary for all file types. It just prevents line endings from being converted.

Rob

Hi, Rob. I tried various case.

params.bodyType = "binary" params.body = { filename = filename, baseDirectory = system.DocumentsDirectory, }

In this case, Response did not return, and the process did not finish.

params.bodyType = "binary" params.body = {}

As same as above, Response did not return, and the process did not finish.

params.bodyType = "binary" params.body = "dummy"

response = “Error in call to API function “files/download”: The request body is supposed to be empty, but it isn’t; got “dummy””

params.bodyType = "binary" params.body = ""

response = “Error in call to API function “files/download”: You provided a non-empty HTTP “Content-Type” header (“application/octet-stream”).  This API function requires that the header be missing or empty.”

params.bodyType = "binary" params.body = nil

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.”

On android, not a way to empty ‘Content-Type’ without setting the body?

Thanks.

What happens if you do params.bodyType = nil

Rob

params.headers["Authorization"] = "Bearer "..M.accessToken params.headers["Dropbox-API-Arg"] = "{\"path\": \"/"..filename.."\"}" params.bodyType = nil

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.”

08:16

 

 

what is automatically setting value to the headers? Corona SDK or android SDK?

If it is Corona SDK, I would like you to prepare a flag does not set a value to the headers.

Can you put together a simple demonstration app that shows the problem. That is an engineer should be able to unzip the sample, load it in the simulator, build for device and run the app and see the error happen. If you can do that, I invite you to submit a bug request using the “Report a Bug” link at the of the page. The submission should contain a complete project (main.lua, config.lua, build.settings and any other assets needed to run) put in a .zip file (no .rar’s please). Attach it to the bug report.

When you complete that you will get an email back with a confirmation of the submission. Please copy the CaseID from the subject of the email and post it back to this thread as a reference.

Thanks

Rob

You need to register to the Dropbox developer, and get your consumer key and secret.

 

https://www.dropbox.com/developers

 

And, you set them to dropbox.lua.

 

Did you file the bug report using the “Report a bug” link at the top of the page?

yes. CaseID is 46753.

Then why not set the bodyType to binary. It doesn’t hurt to use binary for all file types. It just prevents line endings from being converted.

Rob

Hi, Rob. I tried various case.

params.bodyType = "binary" params.body = { filename = filename, baseDirectory = system.DocumentsDirectory, }

In this case, Response did not return, and the process did not finish.

params.bodyType = "binary" params.body = {}

As same as above, Response did not return, and the process did not finish.

params.bodyType = "binary" params.body = "dummy"

response = “Error in call to API function “files/download”: The request body is supposed to be empty, but it isn’t; got “dummy””

params.bodyType = "binary" params.body = ""

response = “Error in call to API function “files/download”: You provided a non-empty HTTP “Content-Type” header (“application/octet-stream”).  This API function requires that the header be missing or empty.”

params.bodyType = "binary" params.body = nil

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.”

On android, not a way to empty ‘Content-Type’ without setting the body?

Thanks.

What happens if you do params.bodyType = nil

Rob

params.headers["Authorization"] = "Bearer "..M.accessToken params.headers["Dropbox-API-Arg"] = "{\"path\": \"/"..filename.."\"}" params.bodyType = nil

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.”

08:16

 

 

what is automatically setting value to the headers? Corona SDK or android SDK?

If it is Corona SDK, I would like you to prepare a flag does not set a value to the headers.

Can you put together a simple demonstration app that shows the problem. That is an engineer should be able to unzip the sample, load it in the simulator, build for device and run the app and see the error happen. If you can do that, I invite you to submit a bug request using the “Report a Bug” link at the of the page. The submission should contain a complete project (main.lua, config.lua, build.settings and any other assets needed to run) put in a .zip file (no .rar’s please). Attach it to the bug report.

When you complete that you will get an email back with a confirmation of the submission. Please copy the CaseID from the subject of the email and post it back to this thread as a reference.

Thanks

Rob

You need to register to the Dropbox developer, and get your consumer key and secret.

 

https://www.dropbox.com/developers

 

And, you set them to dropbox.lua.

 

Did you file the bug report using the “Report a bug” link at the top of the page?

yes. CaseID is 46753.