Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2050] Android: POST with file/blob parameter will cause issue with rails

GitHub Issuen/a
Resolution Date2011-04-17T01:57:55.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
Labelsandroid, httpclient, xhr
ReporterJeff Haynie
AssigneeJeff Haynie


Seems like Ruby on Rails doesn't like a Content-Type header along side a form-data multipart. It will attempt to convert normal form/data key/value pairs into a File Attachment (containing the value) instead.

In iPhone, this Content-Type header is not present and it works fine. So, for normal fields, we should be suppressing this header field to have the same behavior as iOS. Removing this field causes it to work OK.


  1. Jeff Haynie 2011-04-15

    (from [410b2dea89339e948cec2626e1c93822ed556048]) [#2050 state:fixed-in-qa] fixed android issue related to POST with Content-Type for a plain form/data field http://github.com/appcelerator/titanium_mobile/commit/410b2dea89339e948cec2626e1c93822ed556048"> http://github.com/appcelerator/titanium_mobile/commit/410b2dea89339...

  2. Don Thorp 2011-04-15

    How can Thomas reproduce this to move it to a resolved state?

  3. Jeff Haynie 2011-04-15

    the easiest way is to:

    • build a simple RoR app that will print out the values of the incoming post fields. the non-file fields should be text

    • post a mixed POST with both a file and key/value pairs

  4. Jeff Haynie 2011-04-15

    Thomas, I can also share the customer client code if you'd like.

  5. kevinwhinnery 2011-04-15

    I verified that this works on 1.5.0, Android 2.2 and 2.1. Here's my Rails controller code:

       class UploadController < ApplicationController
         def doit
           render :text => "got #{params[:file]} and also #{params[:hello]}, request:\n#{request}"

    And the Titanium code:

       var xhr = Titanium.Network.createHTTPClient();
       var f = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'KS_nav_ui.png');

    xhr.onerror = function(e) {

       Ti.API.info('IN ERROR ' + e.error);
    }; xhr.onload = function(e) {
       Ti.API.info('IN ONLOAD ' + this.responseText);
    }; // open the client xhr.open('POST','')">');
    // send the data xhr.send({image:f,hello:'hello world!',password:'sanford1000',message:'check me out'});
  6. Thomas Huelbert 2011-04-15

    closing due to Kevins awesomeness

JSON Source