Post photos in either 1.8.7 or 1.9.2

This commit is contained in:
Raphael 2010-09-24 15:18:30 -07:00
parent 004e659ee1
commit 999d229225

View file

@ -19,9 +19,15 @@ class PhotosController < ApplicationController
# get file content type
att_content_type = (request.content_type.to_s == "") ? "application/octet-stream" : request.content_type.to_s
# create temporal file
file = Tempfile.new(file_name, {:encoding => 'BINARY'})
begin
file = Tempfile.new(file_name, {:encoding => 'BINARY'})
file.print request.raw_post.force_encoding('BINARY')
rescue RuntimeError => e
raise e unless e.message.include?('cannot generate tempfile')
file = Tempfile.new(file_name) # Ruby 1.8 compatibility
file.print request.raw_post
end
# put data into this file from raw post request
file.print request.raw_post.force_encoding('BINARY')
# create several required methods for this temporal file
Tempfile.send(:define_method, "content_type") {return att_content_type}