app/models/user.rb
# Uploads files from local path for user
Uploads files from local path for user
Uploads files from local path for user
def upload_from_local_path(public: true)
    upload_path = Rails.application.secrets.local_upload_path+"/#{self.id}"
    Dir.chdir(upload_path)
    count = 0
    Dir.foreach(upload_path) do |file|
      if File.ftype(file) == "file"
        begin
          share = Share.new
          share.file = File.open(file)
          share.user = self
          share.public = public
          share.created_at = File.mtime(file)
          share.save
          count += 1
        rescue => ex
          puts "#{ex.class}: #{ex.message}"
        else
          File.delete(file)
        end
      end
    end
    count
  end
def upload_from_local_path ( public : true ) upload_path = Rails . application . secrets . local_upload_path + "/#{self.id}" Dir . chdir ( upload_path ) count = 0 Dir . foreach ( upload_path ) do | file | if File . ftype ( file ) == "file" begin share = Share . new share . file = File . open ( file ) share . user = self share . public = public share . created_at = File . mtime ( file ) share . save count += 1 rescue => ex puts "#{ex.class}: #{ex.message}" else File . delete ( file ) end end end count end
Uploads files from local path for user
Uploads files from local path for user
public
<not_specific>