Existe al menos 3 gemas que podemos usar para esto usemos las oficiales de Amazon:
AMAZON SDK V1
#!/usr/bin/env ruby require 'aws-sdk-v1' #parametros AMAZON region='us-east-1' accesskeyid='<mi_id>' accesskey='<mi_key>' #codigo s3 = AWS::S3.new(:region=>region,:access_key_id => accesskeyid,:secret_access_key => accesskey) bucket = s3.buckets['<mi_bucket>'] data ='<ruta>' type = 'imagen/png' extension = 'png' #nombre pseudo random name = ('a'..'z').to_a.shuffle[0..7].join + ".#{extension}" obj = bucket.objects.create(name,data,{content_type:type,acl:"public_read"}) url = obj.public_url().to_s
AMAZON V2
#!/usr/bin/env ruby require 'aws-sdk' require 'base64' #parametros region='us-east-1' accesskeyid='<mi_id>' accesskey='<mi_key>' #codigo s3=Aws::S3::Resource.new(:access_key_id => accesskeyid,:secret_access_key=>accesskey,:region=> region) #recuperar base64 imagen=Base64.encode64('<ruta/archivo.jpg>') data = Base64.decode64(imagen) obj = s3.bucket('<mi_bucket>').object('<mi_nombre>').upload_file(data)
No comments:
Post a Comment