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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:01:29+00:00 2026-06-17T01:01:29+00:00

Something I’m not getting about the version process… I have a zip file with

  • 0

Something I’m not getting about the version process…

I have a zip file with a file inside, and I want to upload the file as a “version” of the zip:

Uploader:

  version :specificFile do
    process :extract_file
  end

  def extract_file
    file = nil
    Zip::ZipFile.open(current_path) do |zip_file|
      file = zip_file.select{|f| f.name.match(/specificFile/)}.first
      zip_file.extract(file, "tmp/" + file.name.gsub("/", "-")){ true }
    end    
    File.open("tmp/" + file.name.gsub("/", "-"))
  end

Usage:

=link_to "Specific File", instance.uploader.specificFile.url

Only this just nets me two copies of the zip. Clearly, there’s something I’m missing about how version / process works, and I haven’t been able to find documentation that actually explains the magic.

So how do I do this, and what am I missing?

  • 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-17T01:01:31+00:00Added an answer on June 17, 2026 at 1:01 am

    This provided the “why”, although it took a bit to understand:
    How do you create a new file in a CarrierWave process?

    To rephrase, when you go to create a version, carrierwave makes a copy of the file and then passes the process the file path. When the process exits, carrierwave will upload the contents of that path – not the file the process returns, which is what I thought was going on.

    Working code:

      version :specificFile do
        process :extract_file
        def full_filename (for_file = model.logo.file)
          "SpecificFile.ext"
        end
      end
    
      def extract_plist
        file = nil
        Zip::ZipFile.open(current_path) do |zip_file|
          file = zip_file.select{|f| f.name.match(/specificFile/)}.first
          zip_file.extract(file, "tmp/" + file.name.gsub("/", "-")){ true }
        end    
        File.delete(current_path)
        FileUtils.cp("tmp/" + file.name.gsub("/", "-"), current_path)
      end
    

    So, to make what I want to happen, happen, I:

    • Tell carrierwave to use a particular filename. I’m using a hardcoded value but you should be able to use whatever you want.

    • Overwrite the contents of current_path with the contents you want under the version name. In my case, I can’t just overwrite the zip while I’m “in it” (I think), so I make a copy of the file I care about and overwrite the zip via File and FileUtils.

    PS – It would be nice to avoid the duplication of the zip, but it doesn’t look like you can tell carrierwave to skip the duplication.

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

Sidebar

Related Questions

Something I don't understand about transformations. I want to zoom in to say the
Something I'm not to clear about, I understand there are differences between C# and
Something really odd going on here, and I have gone round in circles trying
something here ; and there, oh,that's all! I want to split it by ;
Something I'm curious about.. What would be most efficient to cache the generation of,
Something I have found strange since I started working on GWT is how few
Something like the following xmlns:jsp=http://java.sun.com/JSP/Page seems to not work, any hint? alternatively how can
{something:1,mode:true,number:1234} Because I'm getting a 406 on expecting JSON. It's being generated via Jersey,
Something (who knows, possibly even me, though certainly not intentionally) has changed the keyboard
Something like this quiz for javascript. http://perfectionkills.com/javascript-quiz/ I have searched it but I came

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.