mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -05:00
41528f5d11
The topic_id param is now required using strong_parameters' #require method. If the parameter is missing ActionController::ParameterMissing will be raised instead of Discourse::InvalidParameters.
23 lines
778 B
Ruby
23 lines
778 B
Ruby
class UploadsController < ApplicationController
|
|
before_filter :ensure_logged_in
|
|
|
|
def create
|
|
params.require(:topic_id)
|
|
file = params[:file] || params[:files].first
|
|
|
|
# only supports images for now
|
|
return render status: 415, json: failed_json unless file.content_type =~ /^image\/.+/
|
|
|
|
upload = Upload.create_for(current_user.id, file, params[:topic_id])
|
|
|
|
render_serialized(upload, UploadSerializer, root: false)
|
|
|
|
rescue FastImage::ImageFetchFailure
|
|
render status: 422, text: I18n.t("upload.image.fetch_failure")
|
|
rescue FastImage::UnknownImageType
|
|
render status: 422, text: I18n.t("upload.image.unknown_image_type")
|
|
rescue FastImage::SizeNotFound
|
|
render status: 422, text: I18n.t("upload.image.size_not_found")
|
|
end
|
|
|
|
end
|