Created
May 4, 2020 10:48
-
-
Save 1c7/c29e088aebd73f8325b55a9a89c9f42f to your computer and use it in GitHub Desktop.
Ruby Upload File to AWS S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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