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

  • Home
  • SEARCH
  • 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 7937297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:29:33+00:00 2026-06-03T22:29:33+00:00

I have at base64 encoded string of a image file. I need to save

  • 0

I have at base64 encoded string of a image file. I need to save it using Paper Clip

My Controller code is

 @driver = User.find(6)
 encoded_file = Base64.encode64(File.open('/pjt_path/public/test.jpg').read)
 decoded_file = Base64.decode64(encoded_file)

 @driver.profile_pic =  StringIO.open(decoded_file)
 @driver.save

In my user model

 has_attached_file :profile_pic, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => '/icon.jpg'

Currently the file is saved as a text file(stringio.txt). But when I change the extension to JPG I can view it as image. How can I name the image correctly using StringIO.

I am having rails 3.2, ruby 1.9.2, paperclip 3.0.3

  • 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-03T22:29:35+00:00Added an answer on June 3, 2026 at 10:29 pm

    I fixed the issue by using

    encoded_file = Base64.encode64(File.open('/pjt_path/public/test.jpg').read)
    decoded_file = Base64.decode64(params[:encoded_image])
    begin
      file = Tempfile.new(['test', '.jpg']) 
      file.binmode
      file.write decoded_file
      file.close
      @user.profile_pic =  file
      if @user.save
        render :json => {:message => "Successfully uploaded the profile picture."}
      else
        render :json => {:message => "Failed to upload image"}
      end
    ensure
      file.unlink
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Base64 String that represents a BitMap image. I need to transform
I have a big string (a base64 encoded image) and it is 1050 characters
I have a string of of base64-encoded PNG image that is suitable to use
I have a base64 encoded octet string in a file: \x7D\x1E\x40\xEE\x62\x12\xE1\x9C\xC9\x28\x63\x95\xB6\x0C\xCB\xF7\xD2\x2F\x6F\xA8\xA1\xF5 \x21\x4E\x7A\x4D\x79\x38\x78\xBF\x1B\x2B\x73\x28\x57\x5C\x8F\xB2\x53\xC0\x4C\x57\x6C\x77 \xCF\x88\xA3\xAA\x7D\x52\xEA\x2F\xCD\xE9\x29\x27\xD9\x0F\xA1\xF4\x12\xDB\xBF\x65\x09\x4C \x29\xE9\xC9\xB5\x0F\x3C\xE5\xEC\x82\xBC\x42\x3C\xBB\xE2\xFF\x7B\x7B\xB1\x32\x3F\x4D\xC5
I have a .NET string which is Base64 encoded representation of an array of
I have a base64 encoded PNG. I need to get the color of a
I have a Base64 jpeg image string which is a simple signature image. I
I have an application, currently written in C#, which can take a Base64-encoded string
I have a base64 encoded string that I would like to convert into an
I have to submit a base64 encoded string to my server. How to do

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.