How to use a carrier wave without a model in rails?

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

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

But it throws an ArgumentError (invalid byte sequence in UTF-8)

What am I doing wrong here?

I am sending it through the ios app using AFNetworking.

+5
source share
2 answers

Here is a short 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) 
+2
source

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

Your code should be

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

Source: https://habr.com/ru/post/1236377/


All Articles