[TIMOB-16565] iOS: NewHTTPClient Content-Disposition and the Content-Type not set correctly on POST files
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-03-10T22:07:19.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2014 Sprint 05, 2014 Sprint 05 API, Release 3.3.0 |
Components | iOS |
Labels | module_network, qe-testadded |
Reporter | Pedro Enrique |
Assignee | Pedro Enrique |
Created | 2014-03-06T18:38:43.000+0000 |
Updated | 2014-06-19T12:43:50.000+0000 |
Description
When POSTing files, the filename in Content-Disposition and the Content-Type are not being set properly. See the requests for the old and new below (full requests follow)
Old ASIHttpRequest httpClient:
Content-Disposition: form-data; name="files"; filename="somefile.pdf"
Content-Type: application/pdf
New NSUrlConnection httpClient:
Content-Disposition: form-data; name="files"; filename="file0"
Content-Type: application/octet-stream
Test code:
var win = Titanium.UI.createWindow({
backgroundColor: '#CCC'
});
var startButton = Ti.UI.createButton({
title: 'Start Test',
});
win.add(startButton);
startButton.addEventListener('click', function(){
var xhr = Ti.Network.createNewHTTPClient({
onload: function(e) {
var obj = JSON.parse(this.responseText);
Ti.API.info(obj);
},
onerror: function(e) {
Ti.API.error(e.error);
}
});
xhr.open('POST', 'http://httpbin.org/post');
// xhr.send(Ti.Filesystem.getFile('cricket.wav').read());
// xhr.send({files:Ti.Filesystem.getFile('cricket.wav').read()});
// xhr.send(Ti.Filesystem.getFile('cricket.wav'));
xhr.send({files:Ti.Filesystem.getFile('cricket.wav')});
});
win.open();
Added to PR https://github.com/appcelerator/titanium_mobile/pull/5433
Test Case
Updated PR: https://github.com/appcelerator/titanium_mobile/pull/5433
Here's the updated code. Note: You need a file called "cricket.wav" in your Resources dir
Verified fixed on: Mac OSX 10.9.3 Appcelerator Studio, build: 3.3.0.201405121247 Titanium SDK, build: 3.3.0.v20140515133312 Titanium CLI, build: 3.3.0-dev Alloy: 1.4.0-alpha Used test code provided by Pedro. Content-type correctly showing "Content-Type" = "audio/wav"; Closing.