Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 461 forks source link

how about multi part form data for attach image #179

Open humbroll opened 10 years ago

humbroll commented 10 years ago

I just wonder what kind of param type of attachment(image). Should I define own validator?

humbroll commented 10 years ago

User data like below.

"user"=>{"profile_image"=>#<ActionDispatch::Http::UploadedFile:0x007fe8ad6eaeb8 @tempfile=#<Tempfile:/var/folders/mv/9n4zpk597fgc4hgm69v2dljm0000gn/T/RackMultipart20131224-3012-oayy5p>, @original_filename="blogfiles.naver-1.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[profile_image]\"; filename=\"blogfiles.naver-1.jpeg\"\r\nContent-Type: image/jpeg\r\n">, "email"=>"qwerasdf@sk.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}

iNecas commented 10 years ago

Own validator is probably the way to go

chrise86 commented 10 years ago

@humbroll did you manage to create a file validator?

oliviermilla commented 10 years ago

@chrise86

class FileValidator < Apipie::Validator::BaseValidator

  def validate(value)
    value.is_a?(Rack::Test::UploadedFile) || value.is_a?(ActionDispatch::Http::UploadedFile)
  end

  def self.build(param_description, argument, options, block)
    self.new param_description if argument == File
  end

  def description
    'Must be a valid file'
  end

end
chrise86 commented 10 years ago

@muichkine awesome thanks!

bublik commented 10 years ago

thanks

krrg commented 9 years ago

@muichkine Very helpful, thanks much.

bublik commented 8 years ago

How generate documentation with this validatior.

:show_in_doc gets error

sahilchopra commented 7 years ago

How we can handle base64 image format?

korrs commented 6 years ago

param :file, ActionDispatch::Http::UploadedFile, ... work for me

Kyokatarz commented 2 years ago

@oliviermilla How do I use the custom defined validator?

Do I just do this?:

param :name, CustomValidator, (...)
oliviermilla commented 2 years ago

@oliviermilla How do I use the custom defined validator?

Do I just do this?:

param :name, CustomValidator, (...)

I don't remember, it was 8 years ago. :)