Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3853858
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:32:03+00:00 2026-05-19T17:32:03+00:00

I read the content of a file on my client, base64 encode it, send

  • 0

I read the content of a file on my client, base64 encode it, send it via JSON to my Rails backend, base64 decode it and store the data in the database. I then try to send a email from Rails with the data as a attachement.

Here is my column definition of the binary data:

t.column :binarydata, :binary, :limit => 10.megabytes, :null => false

Here is my mail template:

class MYMailer < ActionMailer::Base
  def mail(from, to, cc, bcc, subject, message, files=[], sent_at = Time.now)
    @subject = subject
    @recipients = to
    @from = from
    @cc = cc
    @bcc = bcc
    @sent_on = sent_at
    @body["message"] = message
    @headers = {}

    # attache files
    files.each do |file|
      attachment file.mimetype do |a|
        a.body = file.binarydata
        a.filename = file.filename
      end
    end

  end
end

Here is where I read from the database and send the email:

attachements = AttachementItem.find(:all)
MYMailer.deliver_mail("foo@home.com", "bar@home.com", nil, nil, "Attachement test", "This is just a test", attachements)

Here is the code that parses the incomming JSON and stores the data in the database:

attachement_json = params[:attachement]
attachement_json = attachement_json.gsub(/\n/, "\\n")
attachement = AttachementItem.new.from_json(attachement_json)
b64data = Base64.decode64(attachement.binarydata)
attachement.binarydata = b64data
attachement.save

However the attachements that I receive in my email is garbage. I do not know if the error is on my client side and I am investigation this also, but can you see if I have a error in my Rails code?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:32:04+00:00Added an answer on May 19, 2026 at 5:32 pm

    Well my Rails code works! I found my errors (there where more than one), and they where all in my client code. Sorry for asking 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can JQuery/JavaScript read/get the file content on the client side, where the file is
I'd like to read whole content of a text file to a std::string object
How to read each revision of file using sharpsvn client using c# ? Not
I'm trying to read the contents of a text file, in this case a
When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from
I`d like to be able to read the content of office documents (for a
I read somewhere in the Microsoft documentation that the content of the ASP.NET's web.config
Can a firefox XPCOM component read and write page content across multiple pages? Scenario:
I am helping a client convert their Perl flat-file bulletin board site from ISO-8859-1
I've written a program that uses fsockopen() and fgets() to read a website's content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.