I think this should be an easy syntax question, but I’m not sure if my approach is correct. I’m using paperclip to accept a file upload from Flash. The action successfully creates the object and saves the upload, but when it tries to generate an XML response with the default XML generator I think it chokes trying to include the paperclip attachment in the XML file. Rails shows a 406 error and Flash throws the I/O error.
I found a good resource on embedding paperclip attachments in XML but this is total overkill. All flash needs is a success or failure message. Something like:
def jpg_stream
@photo = Photo.new(:name => params[:name], :uploaded => Time.now)
@photo.image = params[:image]
respond_to do |format|
if @photo.save
format.xml { "<success/>" }
else
format.xml { render :xml => @photo.errors, :status => :unprocessable_entity }
end
end
end
What should this line be?
format.xml { "<success/>" }
EDIT
This is the error stack trace. I think Rails has no problems returning whatever is generated, the 406 error means the browser/Flash will not accept the response.
Started POST "/generate_jpg" for 127.0.0.1 at 2011-01-25 12:59:24 -0700
Processing by PhotosController#jpg_stream as HTML
Parameters: {"name"=>"Test snapshot", "stream_id"=>"1", "Filename"=>"this.jpg", "image"=>#<ActionDispatch::
Http::UploadedFile:...
[paperclip] identify -format %wx%h "C:/Users/Sam/AppData/Local/Temp/stream20110125-4048-zqbu60.jpg[0]" 2>NUL
←[1m←[35mAREL (1.0ms)←[0m INSERT INTO "photos" ("name", "description", "stream_id", "created_at", "updated_at", "image_file_name", "image_content_type", "image_file_size", "image_updated_at") VALUES ('Test snapshot', '2011-01-25 19:59:24.630999', 1, '2011-01-25 19:59:24.687002', '2011-01-25 19:59:24.687002', 'this.jpg', 'application/octet-stream', 12251, '2011-01-25 19:59:24.651000')
[paperclip] Saving attachments.
[paperclip] saving .../system/images/86/original/this.jpg
Completed 406 Not Acceptable in 108ms
I would try a simpler version first:
render :xml => "<success/>". I.e., droprespond_tocompletely, leave onlyI’m not sure about all nuances of
respond_to(don’t use it myself), but doingformat.xml { "<success/>" }might require a erb template from you.Including error stacktrace would be nice too.