Steps to Reproduce
Using the exact example given in the Titanium docs at
http://docs.appcelerator.com/titanium/latest/#!/guide/File_Uploads_and_Downloads I am unable to successfully transmit a file on iOS, but it *DOES* work fine on Android.
Inspecting further, the POST request's Content-Type is not getting set properly to 'multipart/form-data' when sent from iOS, but instead is sent as 'application/x-www-form-urlencoded'. The property containing the supposed file will exist, but is merely a string representing the file path (as it exists on the mobile device).
I've tried manually setting the Content-Type between opening the connection and sending the data, but it appears to be ignored.
Actual Result
Content Type: application/x-www-form-urlencoded; charset=utf-8
Expected Result
Content Type: multipart/form-data
I wonder if this is perhaps more of a bug with the underlying method of setting request headers, as no matter what I set, it seems to be getting ignored on iOS, but again, everything is working as expected on Android.
Possibly related to TIMOB-13163
To clarify this after a bit more playing around, I'm experiencing this (on iOS) when attempting to use HTTPClient.send() with a File instead of a Blob as part of the data sent. It seems to happen if I'm sending either *just* a File, or a File as a property on a Dictionary/JS Object, ala
as well as
If I instead do something such as
THEN this works as expected on iOS.
https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiNetworkHTTPClientProxy.m#L544 …appears to only handle the case of a TiBlob, but not a TiFile, hence what I described above. So the parameter types described for the "data" property in the docs (http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.Network.HTTPClient-method-send) isn't accurate.
Moving this ticket to engineering based on the detailed analysis from the reporter. Looking at the SDK code, either the code needs to handle File type or documentation needs to be updated. I have not looked at Android code.
I wonder when this will be implemented or at least a temporary workaround to fix this because updating several data with file upload which is optional gets boundary error message. Thanks
This was fixed with the HTTPClient refactor for 3.2.3 The headers for the sample in the documentation are these:
Hello, I just made a POST request and sent a JavaScript object to the send method and here is what I see on WireShark: The content type is: Content-Type: application/x-www-form-urlencoded; charset=utf-8 The data sent is: firstname=John&phone=555555555&lastname=Smith&email=johnsmith@doe.com When I make a Ti.API.info on the JavaScript object right before I send it, I get this printed: [INFO] : { [INFO] : email = "johnsmith@doe.com"; [INFO] : firstname = John; [INFO] : lastname = Doe; [INFO] : phone = 555555555; [INFO] : } From what I can see on this JIRA, it should have been fixed with the 3.2.3 refactor, but I use the 3.2.3 and this is not fixed at all. Jérome
Closed as completed. If this is in error, please reopen.