I have tried everything and still can't get this to work.
I have two types of application in my system that are pre-qualified and sent to lenders,
1) one generates a pdf 2) second should use active storage attachments and attach them to an ActionMailer
First one is working the second is giving me the following error:
[ActionMailer::DeliveryJob] [905177a5-b0e9-46f4-ba9a-fc4630e873f9] Error performing ActionMailer::DeliveryJob (Job ID: 905177a5-b0e9-46f4-ba9a-fc4630e873f9) from Async(mailers) in 140.14ms: Errno::ENOENT (No such file or directory @ rb_sysopen - https://funderhunt.co/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBZ1lIIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--fa91a15681c23d47d767169c7821601aa15ed2b3/Statuses.pages?disposition=attachment):
The link is correct tho:
My mailer code for this part looks like this:
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
What is wrong? Can you please help. Thanks in advance.
If somebody lands here looking for a general solution:
modelname.attachments.each do |file|
attachments[file.blob.filename.to_s] = {
mime_type: file.blob.content_type,
content: file.blob.download
}
end
You should be able to do something like,
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
will return the content of the file, similar to File.read
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With