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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:47:26+00:00 2026-06-12T15:47:26+00:00

I’m using jpegcam to allow a user to take a webcam photo to set

  • 0

I’m using jpegcam to allow a user to take a webcam photo to set as their profile photo. This library ends up posting the raw data to the sever which I get in my rails controller like so:

def ajax_photo_upload
  # Rails.logger.info request.raw_post
  @user = User.find(current_user.id)
  @user.picture = File.new(request.raw_post)

This does not work and paperclip/rails fails when you try to save request.raw_post.

Errno::ENOENT (No such file or directory - ????JFIF???

I’ve seen solutions that make a temporary file but I’d be curious to know if there is a way to get Paperclip to automatically save the request.raw_post w/o having to make a tempfile. Any elegant ideas or solutions out there?

UGLY SOLUTION (Requires a temp file)

class ApiV1::UsersController < ApiV1::APIController

  def create
    File.open(upload_path, 'w:ASCII-8BIT') do |f|
      f.write request.raw_post
    end
    current_user.photo = File.open(upload_path)
  end

 private

  def upload_path # is used in upload and create
    file_name = 'temp.jpg'
    File.join(::Rails.root.to_s, 'public', 'temp', file_name)
  end

end

This is ugly as it requires a temporary file to be saved on the server. Tips on how to make this happen w/o the temporary file needing to be saved? Can StringIO be used?

  • 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-12T15:47:28+00:00Added an answer on June 12, 2026 at 3:47 pm

    The problem with my previous solution was that the temp file was already closed and therefore could not be used by Paperclip anymore. The solution below works for me. It’s IMO the cleanest way and (as per documentation) ensures your tempfiles are deleted after use.

    Add the following method to your User model:

    def set_picture(data)
      temp_file = Tempfile.new(['temp', '.jpg'], :encoding => 'ascii-8bit')
    
      begin
        temp_file.write(data)
        self.picture = temp_file # assumes has_attached_file :picture
      ensure
        temp_file.close
        temp_file.unlink
      end
    end
    

    Controller:

    current_user.set_picture(request.raw_post)
    current_user.save
    

    Don’t forget to add require 'tempfile' at the top of your User model file.

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.