Skip to content
Browse files

Force Tempfile extension when creating a Tempfile

This should fix the problem on animated file detection.

Fixes #851
  • Loading branch information...
1 parent 50635d3 commit 48736ce523b0dbc596dd4bbe0b9d07f264493e5b @sikachu sikachu committed
View
2 NEWS
@@ -1,5 +1,7 @@
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
logging in the AWS is turned on.
* Bug fix: Task "paperclip:refresh:missing_styles" now work correctly.
View
4 lib/paperclip/io_adapters/attachment_adapter.rb
@@ -52,7 +52,9 @@ def cache_current_values
end
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
if src.respond_to? :copy_to_local_file
src.copy_to_local_file(:original, dest.path)
View
4 lib/paperclip/io_adapters/file_adapter.rb
@@ -56,7 +56,9 @@ def path
private
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
FileUtils.cp(src.path, dest.path)
dest
View
4 lib/paperclip/io_adapters/stringio_adapter.rb
@@ -47,7 +47,9 @@ def path
private
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
while data = src.read(16*1024)
dest.write(data)
View
4 lib/paperclip/io_adapters/uploaded_file_adapter.rb
@@ -50,7 +50,9 @@ def path
private
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
FileUtils.cp(src.path, dest.path)
dest
View
12 lib/paperclip/tempfile.rb
@@ -7,14 +7,16 @@ class Tempfile < ::Tempfile
# taken from the comments on this blog post:
# http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
#
- # This is Ruby 1.8.7's implementation.
- def make_tmpname(basename, n)
+ # This is Ruby 1.9.3's implementation.
+ def make_tmpname(prefix_suffix, n)
if RUBY_PLATFORM =~ /java/
- case basename
+ case prefix_suffix
+ when String
+ prefix, suffix = prefix_suffix, ''
when Array
- prefix, suffix = *basename
+ prefix, suffix = *prefix_suffix
else
- prefix, suffix = basename, ''
+ raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
end
t = Time.now.strftime("%y%m%d")

0 comments on commit 48736ce

Please sign in to comment.
Something went wrong with that request. Please try again.