Class: Pressroom::UploadsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Pressroom::UploadsController
- Defined in:
- app/controllers/pressroom/uploads_controller.rb
Overview
Upload endpoint for @editorjs/image.
Answers the tool's contract: { success: 1, file: { url: ... } } on success, { success: 0, message: ... } on refusal.
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/pressroom/uploads_controller.rb', line 9 def create return head :not_found unless Pressroom.active_storage? file = params[:image] return head :bad_request if file.blank? error = rejection_reason(file) return refuse(error) if error blob = ActiveStorage::Blob.create_and_upload!( io: file.tempfile, filename: file.original_filename, content_type: file.content_type ) render json: { success: 1, file: { url: blob_url(blob) } } rescue StandardError => e Rails.logger.warn("pressroom: upload failed: #{e.}") refuse("upload failed") end |