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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:57:53+00:00 2026-06-16T11:57:53+00:00

In my Rails 3 application I have multiple models, and each model is associated

  • 0

In my Rails 3 application I have multiple models, and each model is associated with another model.

User model

has_many :departments
accepts_nested_attributes_for :departments

Department Model

has_many :projects
accepts_nested_attributes_for :projects

I am trying to insert data through the postman REST client using JSON. I have found some of the formats except there is an image upload field in the User model that I am going to handle with the PaperClip gem.

Through my rails view it is working fine, but how do I upload an image using postman?

For uploading through REST client I need the JSON format equivalent of my image.

Is there any way to embed the image in json so I can use the postman rest client?

  • 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-16T11:57:56+00:00Added an answer on June 16, 2026 at 11:57 am

    – Using Base64

    What is Base64
    When you have some binary data that you want to ship across a network, you generally don’t do it by just streaming the bits and bytes over the wire in a raw format. Why? because some media are made for streaming text. You never know — some protocols may interpret your binary data as control characters (like a modem), or your binary data could be screwed up because the underlying protocol might think that you’ve entered a special character combination (like how FTP translates line endings).

    So to get around this, people encode the binary data into characters. Base64 is one of these types of encodings. Why 64? Because you can generally rely on the same 64 characters being present in many character sets, and you can be reasonably confident that your data’s going to end up on the other side of the wire uncorrupted.

    — Taken from What is base 64 encoding used for?


    So one way of doing it is to put a Base64 string inside your json request and have your app decode it.

     # Your request
     {
        'user':{
         # .... 
             'picture':'GIF89a\xB4\x00\x1F\x00\xE7\xFD....'
         }
     }
    

    Here is what your model could do

     class User < ActiveRecord::Base
       def convert_from_base64(image_data)
         data = StringIO.new(Base64.decode64(image_data))
         data.class.class_eval { attr_accessor :original_filename, :content_type }
    
         tmp = Tempfile.new("base64")
         tmp.write(data.read)
         tmp.close
    
         # only on *nix
         data.content_type = IO.popen(["file", "--brief", "--mime-type",tmp.path], 
            in: :close, err: :close).read.chomp
         data.original_filename = "picture." + data.content_type.split("/").last
    
         data
       end
     end
    
    
     # in your controller
     def create
       image_data = JSON.parse(params[:json])['user']['picture'] #or which ever field it is
       params[:user][:picture] = @user.convert_from_base64(image_data)
       # ....  
     end
    

    But a quick look at POSTMAN tells me you have to do the encoding your self.


    Alternatively
    you can just pass a url instead of the data – if the url is pointing to resource available on the net.

    require "open-uri"
    
    class User < ActiveRecord::Base
      def picture_from_url(url)
        self.picture = open(url)
      end
    end
    # then just do 
    user.picture_from_url params[:user][:photo_url]
    

    Update
    Postman actually allows you to construct a post request with an image attached. Isnt that what you are looking for ?

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

Sidebar

Related Questions

I have multiple rails application running at a server. Each one at one port
I have an rails 3 application where there are multiple registrations (diagnosis, patient, laboratory
In my rails application I have two models called Kases and Notes. They work
I have three models in a Rails application: Game represents an instance of a
I have two tables in my rails application Categories and Projects. The relationship between
What I'm basically doing is sharing some models across multiple projects. I have a
Is it possible to have a Rails application from multiple Git repositories? At the
I have rails application that connects to multiple databases. I wrote custom rake task
I have multiple developers working on the same application in rails. I am trying
I have 2 models (Book & Image) class Book < ActiveRecord::Base has_many :images accepts_nested_attributes_for

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.