如何使用rails将base64映像上传到s3?

时间:2019-06-13 04:19:19

标签: ruby-on-rails amazon-s3

我按照本文档的说明与此一起在亚马逊s3中上传图像。

https://gist.github.com/Bijendra/8861700

我要上传base64图像 我有以下代码:

    def savetos3
       imagePath = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAA ETC...'
       service = AWS::S3.new(:access_key_id => 'MYACCESSID',
                          :secret_access_key => 'MYSECRETKEY')
                bucket_name = "MYBUCKETNAME"
                bucket = service.buckets[bucket_name]
                bucket.acl = :public_read
                key = "img/#{downloadID}/#{size}.png"
                s3_file = service.buckets[bucket_name].objects[key].write(:file => imagePath)
                s3_file.acl = :public_read
    end

此错误将显示

"#<Errno::ENAMETOOLONG: File name too long @ rb_sysopen - data:image/jpeg;base64,/9

如何将base64转换为文件?

0 个答案:

没有答案