Class: Api::V3::PhotosController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/v3/photos_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin?, #can?, #current_ability, #current_user, #error!, #error_404!, #optional!, #requires!

Instance Method Details

#createObject

上传图片,请使用 Multipart 的方式提交图片文件

POST /api/v3/photos

params:

file - 文件信息, [required]

14
15
16
17
18
19
20
21
22
# File 'app/controllers/api/v3/photos_controller.rb', line 14

def create
  requires! :file

  @photo = Photo.new
  @photo.image = params[:file]
  @photo.user_id = current_user.id
  @photo.save!
  render json: { image_url: @photo.image.url }
end