Ruby on rails 将活动存储文件附加到邮件程序
我什么都试过了,但还是没能成功 我的系统中有两种类型的应用程序经过资格预审并发送给贷款人 1) 一个生成pdf 2) 第二,应使用活动存储附件并将其连接到ActionMailer 第一个正在工作第二个给我以下错误: [ActionMailer::DeliveryJob][905177a5-b0e9-46f4-ba9a-fc4630e873f9] 执行ActionMailer::DeliveryJob(作业ID: 905177a5-b0e9-46f4-ba9a-fc4630e873f9)在140.14毫秒内从异步(邮件)发送: Errno::enoint(没有这样的文件或目录@rb_sysopen- ): 链接是正确的,如下所示: 此部件的邮件程序代码如下所示:Ruby on rails 将活动存储文件附加到邮件程序,ruby-on-rails,ruby,actionmailer,rails-activestorage,Ruby On Rails,Ruby,Actionmailer,Rails Activestorage,我什么都试过了,但还是没能成功 我的系统中有两种类型的应用程序经过资格预审并发送给贷款人 1) 一个生成pdf 2) 第二,应使用活动存储附件并将其连接到ActionMailer 第一个正在工作第二个给我以下错误: [ActionMailer::DeliveryJob][905177a5-b0e9-46f4-ba9a-fc4630e873f9] 执行ActionMailer::DeliveryJob(作业ID: 905177a5-b0e9-46f4-ba9a-fc4630e873f9)在140.
q = 0
statement.files.each do |file|
q += 1
bank_statement = File.read(rails_blob_url(file, disposition: "attachment"))
attachments["statement_#{q}.pdf"] = { :mime_type => 'application/pdf', :content => bank_statement }
end
怎么了?你能帮忙吗。提前感谢。您应该能够执行以下操作:
statement.files.each_with_index do |file, q|
attachments["statement_#{q + 1}.pdf"] = { mime_type: 'application/pdf', content: file.blob.download }
end
file.blob.download
将返回文件内容,类似于file.read
如果有人来到这里寻找一般解决方案:
modelname.attachments.each do |file|
attachments[file.blob.filename.to_s] = {
mime_type: file.blob.content_type,
content: file.blob.download
}
end
File.read
需要一个本地文件,而不是URL。您好,谢谢,是的,我之前也做过同样的事情,但是,它如何影响内存?系统会将该文件存储在缓存或tmp中吗?之后如何删除它们?Blob#download
被读取到内存中,然后由Ruby的GC收集。如果您将一个块传递给Blob#download
,它将以块的形式流式传输并生成。