[TIMOB-2050] Android: POST with file/blob parameter will cause issue with rails
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:57:55.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 |
Components | Android |
Labels | android, httpclient, xhr |
Reporter | Jeff Haynie |
Assignee | Jeff Haynie |
Created | 2011-04-15T03:09:03.000+0000 |
Updated | 2011-04-17T01:57:55.000+0000 |
Description
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.
Comments
- 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...
- Don Thorp 2011-04-15
How can Thomas reproduce this to move it to a resolved state?
- 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
-
- Jeff Haynie 2011-04-15
Thomas, I can also share the customer client code if you'd like.
- 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}" end end
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','http://10.0.1.91:3000/upload/doit')">http://10.0.1.91:3000/upload/doit');
// send the data xhr.send({image:f,hello:'hello world!',password:'sanford1000',message:'check me out'}); - Thomas Huelbert 2011-04-15
closing due to Kevins awesomeness