In Ruby on Rails, how to set Base64 encoded string as a pdf attachment?
<p>I have a Base64 encoded PDF data and want to set it as an attachment to a mail using ActionMailer.</p>

<p>I have tried like the following (Assume Base64 encoded pdf data is in <code>base64_encoded_string</code>):</p>

<pre><code>attachments['attachment.pdf'] = {
  mime_type: 'application/pdf',
  encoding: 'base64',
  content: base64_encoded_string
}
</code></pre>

<p>But when I open the attached pdf file on the recieved Email, the file is broken.</p>

<p>Now I decode a Base64 string in advance to leave ActionMailer to encode Base64, and it works without any problem.</p>

<pre><code>attachments[File.basename('attachment.pdf')] = Base64.decode64(base64_encoded_string)
</code></pre>

<p>How can you directly set a Base64 encoded string as a pdf attachemnt?</p>