简体   繁体   English

未定义的方法'presigned_post'AWS-SDK gem Rails 4

[英]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.

相关问题 错误:未定义的方法“ presigned_post” - error: undefined method `presigned_post' 使用presigned_post的Rails下载AWS S3文件-致命异常 - Rails download of AWS S3 file using presigned_post - fatal exception Rails 错误 - 无法加载此类文件 -- aws-sdk(您可能需要安装 aws-sdk gem) - Rails Error - cannot load such file -- aws-sdk (You may need to install the aws-sdk gem) Rails.root是否被Amazon AWS-SDK gem覆盖? - Rails.root being overwritten by Amazon AWS-SDK gem? 无法使用AWS-SDK gem启动Rails服务器 - Can't start Rails server with aws-sdk gem 在Rails中使用AWS-SDK Gem,CarrierWave和Sidekiq进行代码转换 - Transcoding with AWS-SDK Gem, CarrierWave, and Sidekiq in Rails 尝试使用回形针和aws-sdk gem发布图像时,出现NoMethodError(nil:NilClass的未定义方法“ first”) - NoMethodError (undefined method `first' for nil:NilClass) when trying to post an image with paperclip and aws-sdk gems NoMethodError-Ruby中AWS-SDK中User:Class的未定义方法'where' - NoMethodError - undefined method 'where' for User:Class in aws-sdk for ruby 如何在 ruby​​ on rails 中使用 aws-s3 或 aws-sdk gem 跨存储桶复制文件 - How to copy file across buckets using aws-s3 or aws-sdk gem in ruby on rails 使用gem'aws-sdk'在Rails应用程序中添加对AWS govCloud的支持 - Add support for aws govCloud in rails applicatioin using gem 'aws-sdk'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM