Skip to content

Instantly share code, notes, and snippets.

@almaron
Created May 14, 2012 16:50
Show Gist options
  • Save almaron/2695017 to your computer and use it in GitHub Desktop.
Save almaron/2695017 to your computer and use it in GitHub Desktop.
Error file upload
From params:
#<ActionDispatch::Http::UploadedFile:0x00000003aa01d8 @original_filename="58.png",
@content_type="image/png",
@headers="Content-Disposition: form-data; name=\"bug[screen]\"; filename=\"58.png\"\r\nContent-Type: image/png\r\n",
@tempfile=#<File:/tmp/RackMultipart20120514-17845-2755c4>>
--------------------------------------------------------
In the model:
def savefile(file_up)
name = file_up.original_filename
File.open(Rails.root.join('public', 'uploads', name), 'w') do |file|
file.write(file_up.read)
end
end
In the conroller:
@bug.savefile params[:bug][:screen]
-----------------------------------------------------------
Error:
Encoding::UndefinedConversionError in BugsController#create
"\x89" from ASCII-8BIT to UTF-8
Trace:
app/models/bug.rb:17:in `write'
app/models/bug.rb:17:in `puts'
app/models/bug.rb:17:in `block in savefile'
app/models/bug.rb:16:in `open'
app/models/bug.rb:16:in `savefile'
app/controllers/bugs_controller.rb:24:in `create'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment