6

I am trying to save a png in my rails app using the below code

uploader = AvatarUploader.new
uploader.store!(params[:image])

But it's throwing ArgumentError (invalid byte sequence in UTF-8)

What am i doing wrong here?

I am posting it via an ios app using AFNetworking.

Kanishka
  • 1,097
  • 5
  • 20
  • 37

2 Answers2

2

Here's a quick excerpt from this answer adapted to your question:

uploader = AvatarUploader.new
File.open(params[:image]) do |file|
  something = uploader.store!(file)
end
uploader.retrieve_from_store!(self.file_name)
Community
  • 1
  • 1
bosskovic
  • 2,034
  • 1
  • 14
  • 29
  • Thanks.. But i ended up using carrierwave-ios gem. That works like a charm. Will test this out sometime. – Kanishka Nov 20 '15 at 13:49
0

If your params[:image] is an instance of either a Tempfile or a StringIO, you should call the method read on this instance.

Your code should be

uploader = AvatarUploader.new
image = params[:image]
uploader.store!(image.read)
Oss
  • 4,232
  • 2
  • 20
  • 35
  • It is the post parameter that i am passing.. I tried your code.. It's throwing "undefined method 'read'" error – Kanishka Nov 20 '15 at 05:34