How to use carrierwave without a model in rails?
Asked Answered
O

2

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.

Oleo answered 19/11, 2015 at 22:38 Comment(0)
O
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)
Objectivity answered 20/11, 2015 at 13:41 Comment(1)
Thanks.. But i ended up using carrierwave-ios gem. That works like a charm. Will test this out sometime.Oleo
V
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)
Veator answered 20/11, 2015 at 0:41 Comment(1)
It is the post parameter that i am passing.. I tried your code.. It's throwing "undefined method 'read'" errorOleo

© 2022 - 2024 — McMap. All rights reserved.