tundrax
2010-Nov-01 01:43 UTC
Encoding::UndefinedConversionError on a simple file upload (rvm, MRI-1.9.2-p0, rails 3.0.1, apache+passenger)
Hello everyone. I am having the encoding issue on a simple file upload action: Encoding::UndefinedConversionError in MainController#upload "\xC4" from ASCII-8BIT to UTF-8 The action looks like this: def upload @uploaded_io = params[:upload] File.open(Rails.root.join(''public'', ''images'', @uploaded_io.original_filename), ''w'') do |file| file.write(@uploaded_io.read) end end I changed File.open to ''wb'' (binary) and it woked fine. I also tried switching the ruby version to 1.8.7 while leaving the File.open method as ''w'' (write) which also worked as expected, without any errors. Should I use ''wb'' everytime I want to use files from the filesystem, or is it the ruby-1.9.2-p0 that comes with RVM cases the issue? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
aarthi r.
2012-Apr-25 10:38 UTC
Re: Encoding::UndefinedConversionError on a simple file upload (rvm, MRI-1.9.2-p0, rails 3.0.1, apac
Hey thanks!.. this solved my problem. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- [Win7 x64] Encoding::UndefinedConversionError after installing when using gem and rails
- dealing with Encoding::UndefinedConversionError: "\xA2" from ASCII-8BIT to UTF-8
- undefined method `original_filename' for nil:NilClass
- Unable to upload images using native rails file upload
- [LLVMdev] Moving return value registers from MRI to return instructions