My clients are trying to upload an image from Blackberry and Android phones. They don't like posting a)form parameters or b) multipart messages. What they would like to do is do a POST to a url with only the data from the file.
Something like this can be done in curl:
curl -d @google.png http://server/postcards/1/photo.json -X POST
I'd like the uploaded photo to put into the photo attribute of the postcards model and into the right directory.
I'm doing something like this in the controller but the image is corrupted in the directory. I am doing a manual renaming of the file to a "png" for now:
def PostcardsController < ApplicationController
...
# Other RESTful methods
...
def photo
@postcard = Postcard.find(params[:id])
@postcard.photo = request.body
@postcard.save
end
The model:
class Postcard < ActiveRecord::Base
mount_uploader :photo, PhotoUploader
end