Sha256: f77fefdfdf9bcbdbe1d841cd36ae4961fe89ab5179b88bfc36b2bf9b6a34fa43

Contents?: true

Size: 772 Bytes

Versions: 2

Compression:

Stored size: 772 Bytes

Contents

# frozen_string_literal: true

module Panda
  module CMS
    module Admin
      class FilesController < ApplicationController
        before_action :authenticate_admin_user!

        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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
panda-cms-0.7.3 app/controllers/panda/cms/admin/files_controller.rb
panda-cms-0.7.2 app/controllers/panda/cms/admin/files_controller.rb