Access file downloads without saving the file, and then email it as an attachment

I am trying to make a form that will send an email with an application using Action Mailer. I do not use the model to return the object that I am loading. I would like to attach the file directly to the message without saving it to the server’s hard drive. In my controller:

def create attachment = params[:attachment].read ApplicationRequestMailer.send_application_to_be_entered(current_user.member, attachment).deliver render :nothing => true end 

In my mail program:

 class ApplicationRequestMailer < ActionMailer::Base def send_application_to_be_entered(member, file) attachment[file.origional_name] = file.read mail(:to => ' test@test.com ', :subject => "To Be Entered") end end 

Is there any way to do this? or do I need to save the file first using something like paperclip?

+4
source share
1 answer

Not sure if this is absolutely correct, but it works:

 def create ApplicationRequestMailer.send_application_to_be_entered(params[:application].read(), params[:application].original_filename).deliver redirect_to dashboards_path, :notice => "Request Sent." end def send_application_to_be_entered(file, filename) attachments[filename] = file mail(:to => ' test@test.com ', :subject => "Application To Be Entered") end 
+4
source

Source: https://habr.com/ru/post/1390709/


All Articles