Skip to content

Instantly share code, notes, and snippets.

@notch8-old
Created April 27, 2012 22:38
Show Gist options
  • Save notch8-old/2513998 to your computer and use it in GitHub Desktop.
Save notch8-old/2513998 to your computer and use it in GitHub Desktop.
def create_upload_file(options = {})
if options[:file]
options = {
"content_type" => "tmp",
"size" => File.size?(options[:file].path),
"tempfile" => options[:file],
"original_filename" => options[:file].path.split(File::SEPARATOR).last
}.merge(options)
elsif options[:data] && options[:file_name]
options = {
"content_type" => "tmp",
"size" => options[:data].size,
"tempfile" => StringIO.new(options[:data]),
"original_filename" => options[:original_filename]
}.merge(options)
else
raise "You need to specify either :file or both :data and :original_filename for this method"
end
Hashie::Mash.new(options)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment