[英]Undefined method 'presigned_post' aws-sdk gem Rails 4
I'm trying to implement direct uploading to S3 via the aws-sdk
gem. 我正在尝试通过aws-sdk
gem直接上传到S3。 For some reason when trying to create the uploaded URL with the presigned_post
method I get an error undefined method 'presigned_post' for nil:NilClass
. 由于某些原因,当尝试使用presigned_post
方法创建上传的URL时,我undefined method 'presigned_post' for nil:NilClass
遇到了一个错误的undefined method 'presigned_post' for nil:NilClass
。 Here's my setup so far: 到目前为止,这是我的设置:
aws.rb aws.rb
Aws.config.update({
region: 'us-east-2',
credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']),
})
S3_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_BUCKET_NAME'])
uploads_controller.rb uploads_controller.rb
def set_s3_direct_post
@s3_direct_post = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
end
I beleive it might have something to do with how the S3_BUCKET
is called, but I've tried it several different ways and it comes back with the same error each time. 我相信它可能与S3_BUCKET
的调用方式有关,但是我尝试了几种不同的方式,但每次都返回相同的错误。
Alex, I ran into this same issue, and it turned out that the order of my initializers was off and my bucket.presigned_post was trying to execute on a null object (bucket). Alex,我遇到了同样的问题,结果是初始化程序的顺序已关闭,而我的bucket.presigned_post试图在空对象(存储桶)上执行。 Take a look at this , and see if it doesn't help you. 看一看 ,看看它是否对您没有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.