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:
* 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.
......
......@@ -52,7 +52,9 @@ module Paperclip
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)
......
......@@ -56,7 +56,9 @@ module Paperclip
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
......
......@@ -47,7 +47,9 @@ module Paperclip
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)
......
......@@ -50,7 +50,9 @@ module Paperclip
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
......
......@@ -7,14 +7,16 @@ module Paperclip
# 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")
......
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