1

EDIT: The real question was whether or not you can use a JSON http header, and how to format an XHR send of a file to a Rails application.

Micah Alcorn
  • 2,363
  • 2
  • 22
  • 45
  • Look, if you're having to hold your titanium rails on with a paperclip, you might want to consider spending less on the whole *titanium* aspect and invest in some screws. \*ahem\* Wait, why does Titanium [make you write your own XHR handler](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network.HTTPClient-object.html)? There aren't any sanity-preserving wrappers for this functionality? – Charles May 05 '11 at 20:19
  • I have read a lot of similar Titanium code, and the xhr seems pretty straightforward (although many other people had trouble finding the solution). I tend to believe that my issue is server-side. I have never used rails outside of the browser. – Micah Alcorn May 05 '11 at 20:26
  • @Micah I think you're correct and I don't think this has to do with the client/Titanium. – rivenate247 May 06 '11 at 16:04
  • Rewritten with a properly singular/plural model and Rails 3 controller methods. The response code is now 201 instead of 200. Unfortunately, nothing shows up in my production log (http://stackoverflow.com/questions/5878335/production-log-not-working), so I can't see if anything is different. – Micah Alcorn May 06 '11 at 18:27
  • UPDATE: added the params variable, nested under model name, and converted to JSON string. Now my 'caption' attribute is successfully stored. Still NULL for the image. – Micah Alcorn May 07 '11 at 00:12
  • @Michah are you sending your image through as a `Ti.Blob` object? – rivenate247 May 07 '11 at 17:02
  • Never heard of that. The code above is everything I have in my app that is related to the camera. I can only find Ti.Blob if I search the API, and it shows no relevant methods. If I try `var blob = image.toBlob();` and then pass `image:blob` in my params, the app never opens the request. – Micah Alcorn May 07 '11 at 19:30

1 Answers1

1

In order to get the file there successfully, you might need to assemble a request with a content-type of "multipart/form-data". Here's a page I found that seems to have the right kind of information to send you in the right direction:

http://www.smokycogs.com/blog/titanium-tutorial-how-to-upload-a-file-to-a-server/

Chris Cherry
  • 28,118
  • 6
  • 68
  • 71