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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:44:05+00:00 2026-05-24T00:44:05+00:00

I have a form with multiple file_field inputs (for images) being handled by Paperclip.

  • 0

I have a form with multiple file_field inputs (for images) being handled by Paperclip.

On my form, once I select an file to upload I want it to immediately upload (on selection!) and show the images thumbnail (without having to submit the completed form with the submit button)

I was able to submit the whole form via ajax using the remotipart gem… but im not sure how to achieve my goal.

Can anyone help? Please let me know if code or more explanation is needed. Many thanks.

  • 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-24T00:44:06+00:00Added an answer on May 24, 2026 at 12:44 am

    I’d approach this problem in following way.

    If you need to upload multiple files via XHR, use http://github.com/valums/file-uploader. It’s a great plugin and it will suit your needs.

    Once you set that up, you should create Rails controller to handle these file uploads (or use existing one). Since you are manually uploading files, you have to write upload function yourself and use paperclip to upload and connect with your Model.

    Let’s say you have a model called Photo. It has attached :photo.

    class UploadsController < ApplicationController
      def upload_photo
        # In order to get contents of the POST request with the photo,
        # you need to read contents of request
        ajax_upload = params[:file].is_a(String)
        file_name = ajax_upload ? params[:file] : params[:file].original_filename
        extension = file_name.split('.').last
    
        # We have to create a temp file which is going to be used by Paperclip for
        # its upload
        tmp_file = "#{Rails.root}/tmp/file.#{extension}"
        file_id = 0
    
        # Check if file with the name exists and generate unique path
        while File.exists?(tmp_file) do
          tmp_file_path = "#{Rails.root}/tmp/file#{file_id}.#{extension}"
          id += 1
        end
    
        # Let's write the file from post request to unique location
        File.open(tmp_file_path, 'wb') do |f|
          if ajax_upload
            f.write request.body.read
          else
            f.write params[:file].read
          end
        end
    
        # Now that file is saved in temp location, we can use Paperclip to mimic one file
        # upload
        @photo = Photo.new :photo => File.open(tmp_file_path)
    
        # We'll return javascript to say that the file is uploaded and put its thumbnail in
        # HTML or whatever else you wanted to do with it
        respond_to do |format|
          if @photo.save
            format.js
          else
           format.js { render :json => { :errors => @photo.errors } }
          end
        end
      end
    end
    

    This is how you can do the AJAX upload of multiple files in Rails with Paperclip.

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

Sidebar

Related Questions

if i have one form that include some input, textarea, select, and multiple file.
I have a php form where multiple images care uploaded. The file names are
I have a form element that contains multiple lines of inputs. Think of each
i have a form that has a multiple select drop down. a user can
I am uploading multiple images (4 file fields) using paperclip, which is working fine
I have a form that allows for multiple file uploads. <input name=uploadedfile[] type=file multiple=true/>
I have a form which uploads multiple file fields into a db using codeigniter.
I have a form with flask-wtf for uploading images, also file field can be
I have a form with multiple fields that I'm validating (some with methods added
I have a form that has multiple fields, and for testing purposes is there

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.