[英]Upload image to S3 Amazon get 0 bytes
I'm trying to upload image png/jpg less than 10 kilobytes to s3 amazon.我正在尝试将小于 10 KB 的图像 png/jpg 上传到 s3 亚马逊。 The upload succeed but the file uploaded and stored with 0 bytes.
上传成功,但上传和存储的文件为 0 字节。
When i'm trying to see the image in the link provided by s3- i get blank.当我试图查看 s3 提供的链接中的图像时,我得到了空白。
If i upload image more bigger than 10 kilobytes size it's ok.如果我上传大于 10 KB 大小的图像,那就没问题了。
Can someone have any idea what is the problem please?有人可以知道有什么问题吗?
file_name = account[:img_token] + File.extname(img.original_filename)
file = Tempfile.new(file_name, encoding: 'ascii-8bit')
file.write(img.read)
path = file.path
bucket_name = 'bucket'
s3 = AWS::S3.new(access_key_id: ENV['S3_ACCESS_KEY'], secret_access_key: ENV['S3_SECRET_ACCESS_KEY'])
link = 'https://s3-eu-west-1.amazonaws.com/' + bucket_name + '/' + file_name
key = file_name
object = s3.buckets[bucket_name].objects[key].write(file: path, acl: 'public-read')
It looks like you are passing a file to the SDK that is seeked to the end of the file.看起来您正在将文件传递给在文件末尾查找的 SDK。 I suspect the SDK is calling
#read
and getting nil back.我怀疑 SDK 正在调用
#read
并返回 nil。 Try rewinding the file first.首先尝试倒带文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.