Sha256: 33dae231547282b6a6eddbc1df8691a97d11114c70dee9bb3b4ec890730c2722

Contents?: true

Size: 565 Bytes

Versions: 4

Compression:

Stored size: 565 Bytes

Contents

require_dependency "bongo/application_controller"

require "aws-sdk-s3"

module Bongo
  class FilesController < ApplicationController
    before_action :authenticate_user!

    skip_before_action :verify_authenticity_token

    def create
      extension = File.extname(params[:file].original_filename)
      s3 = Aws::S3::Resource.new
      obj = s3.bucket(ENV["AWS_S3_BUCKET"]).object(SecureRandom.uuid + extension)
      obj.upload_file(params[:file])

      respond_to do |format|
        format.json { render json: obj.public_url }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bongo-0.2.0 app/controllers/bongo/files_controller.rb
bongo-0.1.1 app/controllers/bongo/files_controller.rb
bongo-0.1.0 app/controllers/bongo/files_controller.rb
bongo-0.0.4 app/controllers/bongo/files_controller.rb