Skip to content

Instantly share code, notes, and snippets.

@1c7
Created May 4, 2020 10:48
Show Gist options
  • Save 1c7/c29e088aebd73f8325b55a9a89c9f42f to your computer and use it in GitHub Desktop.
Save 1c7/c29e088aebd73f8325b55a9a89c9f42f to your computer and use it in GitHub Desktop.
Ruby Upload File to AWS S3
require 'aws-sdk-s3' # v2 version use: require 'aws-sdk'
Aws.config.update({
credentials: Aws::Credentials.new('x', 'x')
})
s3 = Aws::S3::Resource.new(region: 'cn-north-1')
# Beijing: cn-north-1
# Ningxia: cn-northwest-1
file = './test_file_to_s3_bucket.txt'
bucket = '<you bucket name>'
# Get just the file name
name = File.basename(file)
# Create the object to upload
obj = s3.bucket(bucket).object(name)
# Upload it
obj.upload_file(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment