0

I have a problem, I'm using Listen gem to tracking folder for new files added, after added a new file I want to copy it to the other storage with Shrine, but Listen gem return me in "added" variable a path to added file, but Shrine is need a object to run correct, how I can get object if I have a path to this file? Can someone help me?


load './config/initializers/shrine.rb'

module FileTracker

  file_dir = "./public/uploads/cache"

  listener = Listen.to(file_dir) do |modified, added, removed|
    puts "modified absolute path: #{modified}"
    puts "added absolute path: #{added}"
    puts "removed absolute path: #{removed}"
  FileUtils.cp_r added, './public/uploads/store' # this code is copy files, but i need do it with Shrine
  #added.each { |file| p Shrine.new(:store).path(file) } #this code is return error
  end

   listener.start 
   sleep
end

1 Answers1

0

You can call File.open with the path as the argument to create an IO object from a path.

added.each { |path| Shrine.new(:store).upload(File.open(path)) }
Janko
  • 8,985
  • 7
  • 34
  • 51