w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to prevent duplicate file upload using paperclip

To change the name of the file you are uploading, add this in development.rb and production.rb with the options that you want.

  config.paperclip_defaults = {
    :url => "/posts/:id.:extension",
    :path => "#{Rails.root}/public/posts/:id.:extension",
  }  

To get the filename after uploading, you can use:

File.basename(model.avatar.path)

To prevent duplicates, store the checksum (read more) of your uploaded file in a separate column. On new attachment, compare the checksum of the new one with the existing rows.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.