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 7858455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:26:55+00:00 2026-06-02T21:26:55+00:00

I am trying to send a model as json. The model has binary data

  • 0

I am trying to send a model as json. The model has binary data in one of it’s columns. For another model I have used

format.json {self.encode64(@resource_type.data).to_json}

with success, but in that case I only wanted the data column, and not the title etc. What can I do when I want contents from several columns, where only one column’s content should be encoded with encode64?

In the following code, I don’t know where to put the self.encode64 method.

format.json { render :json => @resource.to_json(:only => [:id, :title, :data])}

How can I do this?

  • 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-06-02T21:26:57+00:00Added an answer on June 2, 2026 at 9:26 pm

    You have a few options here.

    You could add a data_base64 method to your model that returned the data in base-64 format and then use the :methods option to to_json in your controller:

    @resource.to_json(:only => [ :id, :title ], :methods => :data_base64)
    

    That would give you a data_base64 key in the JSON instead of data but that might not be a problem.

    You could also use as_json to get a hash and fix the encoding in the controller:

    json = @resource.as_json(:only => [ :id, :title, :data ])
    json['resource']['data'] = self.encode64(json['resource']['data'])
    render :json => json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send an email to multiple users. I have a model
I'm trying to understand how to build a self referencing model for hierachical data.
Trying to send a complex type between two systems that have the same code
im trying to send rest api Users.getLoggedInUser i have all the secret session and
this is the method I want to send data to it function get_lesson($reshte,$poodeman){ $this->load->model('dropdown_model');
Previously i wrote an app that used reflection to serialize data from json to
I am trying to send a model to ASP.NET MVC controller action, but for
I am trying to send my model back to the controller with 2 values
I have a data Store that gets it's information from a JSON api on
Actually I am trying to send data from jQuery to Spring controller and in

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.