Recommended way to generate a presigned url to S3 Bucket in Ruby

后端 未结 2 466
广开言路
广开言路 2021-02-13 18:44

I am trying to generate a pre-signed url on my Rails server to send to the browser, so that the browser can upload to S3.

It seems like aws-sdk-s3 is the ge

2条回答
  •  忘了有多久
    2021-02-13 19:05

    This will work using the aws-sdk-s3 gem

    aws_client = Aws::S3::Client.new(
      region:               'us-west-2', #or any other region
      access_key_id:        AWS_ACCESS_KEY_ID,
      secret_access_key:    AWS_SECRET_ACCESS_KEY
    )
    
    
    s3 = Aws::S3::Resource.new(client: aws_client)
    bucket = s3.bucket('bucket-name')
    obj = bucket.object("${filename}-#{SecureRandom.uuid}")
    
    url = obj.presigned_url(:put)
    

    additional http verbs:

    obj.presigned_url(:put)                              
    obj.presigned_url(:head)                    
    obj.presigned_url(:delete)
    

提交回复
热议问题