Post photos in either 1.8.7 or 1.9.2
This commit is contained in:
parent
004e659ee1
commit
999d229225
1 changed files with 8 additions and 2 deletions
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Reference in a new issue