0

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?

Community
  • 1
  • 1
Thanks for all the fish
  • 1,671
  • 3
  • 17
  • 31

1 Answers1

1

If the image is hosted on a remote server, and this server is available from where you are trying to save the image. You can try this https://stackoverflow.com/a/5007665/1822298 .

Community
  • 1
  • 1
Nakort
  • 76
  • 3
  • The image is sent from a mobile phone. So, there's no way the image can be saved from a server. And definitely it would be obvious to save the image from the URL instead. But I need to receive the file and store it. – Thanks for all the fish Nov 14 '12 at 14:31