Created
November 15, 2018 06:37
-
-
Save moreta/8ec24b772b5b99acfaa0af1705d35148 to your computer and use it in GitHub Desktop.
ruby image base64 string upload to s3
This file contains hidden or 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
class CustomFileStringIO < StringIO | |
def initialize(*args) | |
super(*args[1..-1]) | |
@file_name = args[0] | |
end | |
def original_filename | |
@file_name | |
end | |
end |
This file contains hidden or 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
image_base64 = '"data:image/png;base64,xxxxx'.split(',') | |
file_io = CustomFileStringIO.new(image_file_name, Base64.decode64(image_base64[1])) | |
obj = S3_BUCKET.object(file_io.original_filename) | |
obj.put({ body: file_io }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require 'aws-sdk-s3'
def upload_file
s3 = Aws::S3::Client.new(
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: ENV['AWS_REGION']
)
service = Aws::S3::Resource.new(client: s3)
end