Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19817] Android: HTTPClient multipart header error

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-10-28T21:28:00.000+0000
Affected Version/sRelease 5.0.2
Fix Version/sRelease 5.1.0, Release 5.0.3, Release 5.2.0
ComponentsAndroid
Labelsandroid
Reportergrebulon
AssigneeAshraf Abu
Created2015-10-12T13:19:24.000+0000
Updated2015-10-29T22:26:23.000+0000

Description

The following code (upload a blob to the server), creates malformed http header: {noformat} var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function() {...}; xhr.open('POST',serverUrl'); xhr.send({file:aBlob,name:'something'}); {noformat} This creates the request: {noformat} POST /api/1/upload/ HTTP/1.1 Accept-Encoding: identity X-Titanium-Id: 12345678-2222-4444-8888-111111111111 Content-Type: multipart/form-data; boundary=j7D5qBH3i-pbXOzjDHVJNdQRhPBvF-Q0PUmVjZe ... Content-Length: 56789 --j7D5qBH3i-pbXOzjDHVJNdQRhPBvF-Q0PUmVjZe Content-Disposition: form-data; name="file""; filename="tixhr1851009574.png" Content-Type: image/png Content-Transfer-Encoding: binary ... {noformat} Note the double quotes for the name part: Content-Disposition: form-data; name=*"file""*; filename="tixhr1851009574.png" I've traced the bug to TiHTTPClient.java at addFilePart(String name, ContentBody contentBody). The extra " comes when appending the filename argument.

Comments

  1. Ashraf Abu 2015-10-28

    Master PR: https://github.com/appcelerator/titanium_mobile/pull/7358 5_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/7360 5_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/7361
  2. Ashraf Abu 2015-10-28

    Testing steps to ensure all is okay:-
       Titanium.UI.setBackgroundColor('#000');
        
       var win = Titanium.UI.createWindow({  
           title:'TIMOB',
           backgroundColor:'#fff'
       });
        
        
       var button = Ti.UI.createButton({title: "Press Button",
       								top: 200});
        
       button.addEventListener("click", function(e) {
       	var xhr = Ti.Network.createHTTPClient({
               onload: function(e) {
                   alert("Received: Status = " + this.status + ", Value = " + this.responseText);
                   Ti.API.info("Received: Status = " + this.status + ", Value = " + this.responseText);
               },
               onerror: function(e) {
                   alert("Error: Status = " + this.status + ", Value = " + this.responseText, " error:" + e.error);
               }
           });
        
        	var args = {
        		name: 'testName',
        		file: Ti.Filesystem.getFile("mytestfile.txt")
        	};
        
           xhr.open("POST", "http://httpbin.org/post");
           xhr.send(args);
       });
        
       win.add(button);
        
       win.open();
       
  3. Ashraf Abu 2015-10-28

    Thanks [~buddyguards] for tracing this.
  4. Lokesh Choudhary 2015-10-29

    Verified the fix. No HTTP multipart header error seen. Closing. Environment: Appc Studio : 4.4.0.201510290507 Ti SDK : 5.1.0.v20151028190028 , 5.2.0.v20151029134437, 5.0.3.v20151028143139 Ti CLI : 5.0.5 Alloy : 1.7.18 MAC Yosemite : 10.10.5 Appc NPM : 4.2.1-6 Appc CLI : 5.1.0-38 Node: v0.10.37 samsung Galaxy S4 - Android 4.4.4

JSON Source