Commit 48736ce5 by Prem Sichanugrist

Force Tempfile extension when creating a Tempfile

This should fix the problem on animated file detection.

Fixes #851
parent 50635d35
Unreleased: Unreleased:
* Bug fix: ThumbnailProcessor now correctly detects and preserve animated GIF.
* Bug fix: File extension is now preserved in generated Tempfile from adapter.
* Bug fix: Uploading file with unicode file name now won't raise an error when * Bug fix: Uploading file with unicode file name now won't raise an error when
logging in the AWS is turned on. logging in the AWS is turned on.
* Bug fix: Task "paperclip:refresh:missing_styles" now work correctly. * Bug fix: Task "paperclip:refresh:missing_styles" now work correctly.
......
...@@ -52,7 +52,9 @@ module Paperclip ...@@ -52,7 +52,9 @@ module Paperclip
end end
def copy_to_tempfile(src) def copy_to_tempfile(src)
dest = Tempfile.new(src.original_filename) extension = File.extname(src.original_filename)
basename = File.basename(src.original_filename, extension)
dest = Tempfile.new([basename, extension])
dest.binmode dest.binmode
if src.respond_to? :copy_to_local_file if src.respond_to? :copy_to_local_file
src.copy_to_local_file(:original, dest.path) src.copy_to_local_file(:original, dest.path)
......
...@@ -56,7 +56,9 @@ module Paperclip ...@@ -56,7 +56,9 @@ module Paperclip
private private
def copy_to_tempfile(src) def copy_to_tempfile(src)
dest = Tempfile.new(original_filename) extension = File.extname(original_filename)
basename = File.basename(original_filename, extension)
dest = Tempfile.new([basename, extension])
dest.binmode dest.binmode
FileUtils.cp(src.path, dest.path) FileUtils.cp(src.path, dest.path)
dest dest
......
...@@ -47,7 +47,9 @@ module Paperclip ...@@ -47,7 +47,9 @@ module Paperclip
private private
def copy_to_tempfile(src) def copy_to_tempfile(src)
dest = Tempfile.new(original_filename) extension = File.extname(original_filename)
basename = File.basename(original_filename, extension)
dest = Tempfile.new([basename, extension])
dest.binmode dest.binmode
while data = src.read(16*1024) while data = src.read(16*1024)
dest.write(data) dest.write(data)
......
...@@ -50,7 +50,9 @@ module Paperclip ...@@ -50,7 +50,9 @@ module Paperclip
private private
def copy_to_tempfile(src) def copy_to_tempfile(src)
dest = Tempfile.new(original_filename) extension = File.extname(original_filename)
basename = File.basename(original_filename, extension)
dest = Tempfile.new([basename, extension])
dest.binmode dest.binmode
FileUtils.cp(src.path, dest.path) FileUtils.cp(src.path, dest.path)
dest dest
......
...@@ -7,14 +7,16 @@ module Paperclip ...@@ -7,14 +7,16 @@ module Paperclip
# taken from the comments on this blog post: # taken from the comments on this blog post:
# http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions # http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
# #
# This is Ruby 1.8.7's implementation. # This is Ruby 1.9.3's implementation.
def make_tmpname(basename, n) def make_tmpname(prefix_suffix, n)
if RUBY_PLATFORM =~ /java/ if RUBY_PLATFORM =~ /java/
case basename case prefix_suffix
when String
prefix, suffix = prefix_suffix, ''
when Array when Array
prefix, suffix = *basename prefix, suffix = *prefix_suffix
else else
prefix, suffix = basename, '' raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
end end
t = Time.now.strftime("%y%m%d") t = Time.now.strftime("%y%m%d")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment