Class: Panda::CMS::Admin::FilesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/panda/cms/admin/files_controller.rb

Instance Method Summary collapse

Methods included from Panda::CMS::ApplicationHelper

#active_link?, #block_link_to, #component, #level_indent, #menu_indent, #nav_class, #nav_highlight_colour_classes, #panda_cms_editor, #panda_cms_form_with, #selected_nav_highlight_colour_classes, #table_indent, #title_tag

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/panda/cms/admin/files_controller.rb', line 7

def create
  file = params[:image]
  return render json: {success: 0} unless file

  blob = ActiveStorage::Blob.create_and_upload!(
    io: file,
    filename: file.original_filename,
    content_type: file.content_type
  )

  render json: {
    success: true,
    file: {
      url: Rails.application.routes.url_helpers.rails_blob_url(blob, only_path: true),
      name: blob.filename.to_s,
      size: blob.byte_size
    }
  }
end