Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16380] iOS: HTTPClient on iOS will not POST as multipart/form-data (but Android does)

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDone
Resolution Date2016-03-07T19:15:25.000+0000
Affected Version/sRelease 3.2.0
Fix Version/sn/a
ComponentsiOS
Labelslook1
ReporterJames Hardwick
AssigneePedro Enrique
Created2014-02-03T23:05:50.000+0000
Updated2018-08-06T17:34:43.000+0000

Description

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

Comments

  1. James Hardwick 2014-02-03

    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.
  2. James Hardwick 2014-02-03

    Possibly related to TIMOB-13163
  3. James Hardwick 2014-02-04

    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
       HTTPClient.send(someFile)
       
    as well as
       HTTPClient.send({myfile: someFile})
       
    If I instead do something such as
       HTTPClient.send({myfile: someFile.read()})
       
    THEN this works as expected on iOS.
  4. James Hardwick 2014-02-04

    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.
  5. Ritu Agrawal 2014-02-05

    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.
  6. Rey Bumalay 2014-02-10

    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
  7. Pedro Enrique 2014-06-03

    This was fixed with the HTTPClient refactor for 3.2.3 The headers for the sample in the documentation are these:
       "Content-Length" = 2886522;
       "Content-Type" = "multipart/form-data; charset=utf-8; boundary=0xTibOuNdArY_1401790519";
       
  8. Jérôme Brunel 2014-06-13

    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
  9. Eric Merriman 2018-08-06

    Closed as completed. If this is in error, please reopen.

JSON Source