aws-sdk for Ruby access folder within bucket

后端 未结 5 1111
[愿得一人]
[愿得一人] 2020-12-25 08:09

I have a bucket on the Amazon S3 with the folder in it. I\'m trying to access it the following way via aws-sdk gem:

s3 = AWS::S3.new(
    :         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 09:09

    In case anyone is looking for this, here is how it should work according to https://github.com/aws/aws-sdk-ruby

    creds = JSON.load(File.read('secrets.json'))
    Aws.config[:credentials] = Aws::Credentials.new(creds['AccessKeyId'], creds['SecretAccessKey'])
    Aws.config[:region] = 'us-east-1'
    
    client = Aws::S3::Client.new(
        region: Aws.config[:region],
        credentials: Aws.config[:credentials]
    )
    
    File.open('/local_directory/picture.jpg', 'rb') do |file|
      client.put_object(bucket: 'bucket', key: 'folder_inside_bucket/picture.jpg', body: file)
    end
    

提交回复
热议问题