Sha256: 0ef74fcd3f5c0bafff70bd94295b664df9a3ac24593e92c6023952bba9120ba4

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

class UploadedFilesController < ApplicationController
  def file_upload
    # FIX IE
    if request.headers["HTTP_ACCEPT"].split(",").map(&:strip).include?("application/json")
      content_type = "application/json"
    else
      content_type = "text/plain"
    end

    uploaded_file = UploadedFile.new(file: params[:files][0])
    if uploaded_file.save
      render json: {
        files: [
          {
            "name" => uploaded_file.read_attribute(:file_file_name),
            "size" => uploaded_file.read_attribute(:file_file_size),
            "url" => uploaded_file.file.url,
            "id" => uploaded_file.id
          }
        ]
      }, content_type: content_type
    else
      render json: {
        error: {
          "message" => "An error prevents the uploaded file to be saved"
        }
      }, content_type: content_type
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ouvrages_file_uploader-0.0.3 app/controllers/uploaded_files_controller.rb