How to create a new file in the CarrierWave process?

My user uploads a zip file with 3 files (A.ttf, A.svg, A.otf), and I want to save the original zip plus 3 font files inside it. I created 3 versions with this code

version :ttf
    process :font => :ttf
end

version :svg
    process :font => :svg
end

version :otf
    process :font => :otf
end

It successfully saves 4 copies of the source file, all with the correct file name. However, I do not know how to force CarrierWave to store separate files. This code does not work.: (

def font(format)
  new_file = nil

  # Loop through the zip file and extract the files
  Zip::ZipFile.open(@file.file) do |files|
    files.each do |f|
      next unless f.file?

      filename  = f.name.split("/").last
      ext       = filename.split('.').last

      # Save the file with the proper file extension
      new_file = f if ext == format
  end

  # Return the file to be stored by CarrierWave
  new_file
end
+3
source share
2 answers

, , , . , CarrierWave . , CW ([ ] _original_filename) current_path. , , ( , ..), , CW .

- , , , . , . .:/

+5

CarrierWave. zip . , ? , ?

0

Source: https://habr.com/ru/post/1791445/


All Articles