Merge pull request #20 from insales/named_to_file

Assignment to result of to_file preserves original filename
This commit is contained in:
printercu
2019-02-08 21:07:55 +05:30
committed by GitHub
2 changed files with 4 additions and 1 deletions

View File

@@ -440,6 +440,7 @@ module Paperclip
extname = File.extname(original_filename)
basename = File.basename(filename, extname)
file = Tempfile.new([basename, extname]).tap(&:binmode)
file.original_filename = filename
file.write(body)
file.tap(&:flush).tap(&:rewind)
end

View File

@@ -22,9 +22,11 @@ module Paperclip
end
end
attr_writer :original_filename
# Returns the file's normal name.
def original_filename
File.basename(self.path)
@original_filename ||= File.basename(path)
end
# Returns the size of the file.