gpt4 book ai didi

rails-activestorage - Rails 5.2.0 images.attach 导致 InvalidSignature 错误

转载 作者:行者123 更新时间:2023-12-03 23:16:08 29 4
gpt4 key购买 nike

我正在升级到 Rails 5.2.0 并尝试使用 ActiveStorage 来保存数据馈送中的图像。在 development.rb我有 config.active_storage.service = :local并且模型有 has_many_attached :imagesstorage.yml有默认 :local设置和 Controller Action 有

def listing_params
params.require(:listing).permit(:beds, :baths, :price, :parking, :description, :active, :prop_type, :latitude, :longitude, :address, :city, :city_id, :state, :state_id, :zip, :lo_name, :la_fname, :la_lname, :la_phone, :la_email, :mlsid, :cp, :st_number, :st_suffix, :baths_full, :baths_half, :status, :modtime, :st_name, :featured, :school_id, :picture_count, :parking_type, images: [])
end

我的代码在这条线上挂了
listing.images.attach(pics)出现此错误: ActiveSupport::MessageVerifier::InvalidSignature: ActiveSupport::MessageVerifier::InvalidSignature
我的代码:
def perform
require 'aws-sdk-s3'
require 'rets'

client = Rets::Client.new({
login_url: LOGIN_URL,
username: LOGIN,
password: PASSWORD,
version: VERSION
})

begin
client.login
rescue => e
puts 'Error: ' + e.message
exit!
end

p "Logged in"

Listing.find_each do |listing|
mlsid = listing.mlsid
photos = client.objects '*', {
resource: 'Property',
object_type: 'Photo',
resource_id: mlsid
}
p "about to attempt to attach #{photos.count} images to listing#{listing.id}"
pics = []
photos.each do |data|
pics << data.body
end
listing.images.attach(pics)
puts "#{photos.count} images attached to listing##{listing.id}"
end
end

使用 --trace 运行后的完整错误:
tomb$ rake update:listing_images --trace
** Invoke update:listing_images (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute update:listing_images
Cookie#domain returns dot-less domain name now. Use Cookie#dot_domain if you need "." at the beginning.
"Logged in"
"about to attempt to attach 16 images to listing2873"
rake aborted!
ActiveSupport::MessageVerifier::InvalidSignature: ActiveSupport::MessageVerifier::InvalidSignature
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.2.0/lib/active_support/message_verifier.rb:176:in `verify'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activestorage-5.2.0/app/models/active_storage/blob.rb:43:in `find_signed'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activestorage-5.2.0/lib/active_storage/attached.rb:30:in `create_blob_from'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activestorage-5.2.0/lib/active_storage/attached/many.rb:26:in `block in attach'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activestorage-5.2.0/lib/active_storage/attached/many.rb:22:in `collect'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activestorage-5.2.0/lib/active_storage/attached/many.rb:22:in `attach'
/Users/tomb/Projects/schoolsparrow/app/jobs/listing_image_job.rb:43:in `block in perform'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:70:in `block (2 levels) in find_each'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:70:in `each'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:70:in `block in find_each'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:136:in `block in find_in_batches'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:238:in `block in in_batches'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:222:in `loop'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:222:in `in_batches'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:135:in `find_in_batches'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/relation/batches.rb:69:in `find_each'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activerecord-5.2.0/lib/active_record/querying.rb:11:in `find_each'
/Users/tomb/Projects/schoolsparrow/app/jobs/listing_image_job.rb:31:in `perform'
/Users/tomb/Projects/schoolsparrow/lib/tasks/update.rake:21:in `block (2 levels) in <top (required)>'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `block in execute'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `each'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `execute'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:193:in `invoke_with_call_chain'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:182:in `invoke'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:160:in `invoke_task'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `each'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block in top_level'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:125:in `run_with_threads'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:110:in `top_level'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:83:in `block in run'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:80:in `run'
/Users/tomb/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/Users/tomb/.rbenv/versions/2.3.7/bin/rake:22:in `load'
/Users/tomb/.rbenv/versions/2.3.7/bin/rake:22:in `<main>'
Tasks: TOP => update:listing_images

最佳答案

您正在传递一个数组 Rets::Parser::Multipart::Part反对 ActiveStorage::Attached::Many#attach .它不知道如何处理它们。

每张照片,请调用#attach带有 IO 和文件名:

photos.each_with_index do |photo, index|
listing.images.attach(io: StringIO.new(photo.body), filename: "photo-#{index + 1}.png")
end

关于rails-activestorage - Rails 5.2.0 images.attach 导致 InvalidSignature 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50412513/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com