I have an api and I need to receive image files from a mobile device or some other device but server without a form. And I want to check which user based on the mac_address variable.
The model has the following code:
class Image < ActiveRecord::Base
attr_accessible :mac_address, :superclass_id, :user_id, :file_path, :file_size
belongs_to :mac_address
mount_uploader :file_path, FileUploader
end
The file uploader is just:
class FileUploader < CarrierWave::Uploader::Base
storage :fog
include CarrierWave::MimeTypes
process :set_content_type
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
It already works if I save the file as JSON base64 base. But my colleague wants to send as multipart.
I tried the following suggestion but it doesn't work: Uploading a raw file to Rails using Carrierwave
Ideally, I want my colleague to send the image to:
http://localhost:3000/api/v1/images/MAC_ADDRESS?filename=something.png
So what should I do in he controller to receive that file? It's easy to do a form from rails but this way seems to be impossible to do.
How should I proceed?