Attach active storage file to mailer
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.
ruby-on-rails ruby actionmailer rails-activestorage
add a comment |
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.
ruby-on-rails ruby actionmailer rails-activestorage
File.read
expects a local file, not a URL.
– Josh Brody
Dec 31 '18 at 22:03
add a comment |
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.
ruby-on-rails ruby actionmailer rails-activestorage
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.
ruby-on-rails ruby actionmailer rails-activestorage
ruby-on-rails ruby actionmailer rails-activestorage
asked Dec 31 '18 at 19:02
Ermek Rysbek UuluErmek Rysbek Uulu
133
133
File.read
expects a local file, not a URL.
– Josh Brody
Dec 31 '18 at 22:03
add a comment |
File.read
expects a local file, not a URL.
– Josh Brody
Dec 31 '18 at 22:03
File.read
expects a local file, not a URL.– Josh Brody
Dec 31 '18 at 22:03
File.read
expects a local file, not a URL.– Josh Brody
Dec 31 '18 at 22:03
add a comment |
1 Answer
1
active
oldest
votes
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
.
Hi thanks, yes I did the same right before, however, how does it affect memory? Will the system store that file in cache or tmp? How can I delete them afterward?
– Ermek Rysbek Uulu
Jan 2 at 17:16
Blob#download
gets read into memory and then later collected by Ruby's GC. If you pass a block toBlob#download
it will streamed and yielded in chunks.
– Josh Brody
Jan 2 at 18:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53990639%2fattach-active-storage-file-to-mailer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
.
Hi thanks, yes I did the same right before, however, how does it affect memory? Will the system store that file in cache or tmp? How can I delete them afterward?
– Ermek Rysbek Uulu
Jan 2 at 17:16
Blob#download
gets read into memory and then later collected by Ruby's GC. If you pass a block toBlob#download
it will streamed and yielded in chunks.
– Josh Brody
Jan 2 at 18:47
add a comment |
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
.
Hi thanks, yes I did the same right before, however, how does it affect memory? Will the system store that file in cache or tmp? How can I delete them afterward?
– Ermek Rysbek Uulu
Jan 2 at 17:16
Blob#download
gets read into memory and then later collected by Ruby's GC. If you pass a block toBlob#download
it will streamed and yielded in chunks.
– Josh Brody
Jan 2 at 18:47
add a comment |
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
.
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
.
answered Dec 31 '18 at 22:07
Josh BrodyJosh Brody
3,0881821
3,0881821
Hi thanks, yes I did the same right before, however, how does it affect memory? Will the system store that file in cache or tmp? How can I delete them afterward?
– Ermek Rysbek Uulu
Jan 2 at 17:16
Blob#download
gets read into memory and then later collected by Ruby's GC. If you pass a block toBlob#download
it will streamed and yielded in chunks.
– Josh Brody
Jan 2 at 18:47
add a comment |
Hi thanks, yes I did the same right before, however, how does it affect memory? Will the system store that file in cache or tmp? How can I delete them afterward?
– Ermek Rysbek Uulu
Jan 2 at 17:16
Blob#download
gets read into memory and then later collected by Ruby's GC. If you pass a block toBlob#download
it will streamed and yielded in chunks.
– Josh Brody
Jan 2 at 18:47
Hi thanks, yes I did the same right before, however, how does it affect memory? Will the system store that file in cache or tmp? How can I delete them afterward?
– Ermek Rysbek Uulu
Jan 2 at 17:16
Hi thanks, yes I did the same right before, however, how does it affect memory? Will the system store that file in cache or tmp? How can I delete them afterward?
– Ermek Rysbek Uulu
Jan 2 at 17:16
Blob#download
gets read into memory and then later collected by Ruby's GC. If you pass a block to Blob#download
it will streamed and yielded in chunks.– Josh Brody
Jan 2 at 18:47
Blob#download
gets read into memory and then later collected by Ruby's GC. If you pass a block to Blob#download
it will streamed and yielded in chunks.– Josh Brody
Jan 2 at 18:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53990639%2fattach-active-storage-file-to-mailer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
File.read
expects a local file, not a URL.– Josh Brody
Dec 31 '18 at 22:03