Commit 522a53e3 by Prem Sichanugrist

Ensure that we cache attachment's file name before we perform assignment

There was an issue on assignment another S3 attachment object to another object whereas calling #to_file on S3 attachment will create a Tempfile, which would then having a different file name than original version.

By caching the filename first before calling #to_file, we're ensuring that filename is the original one.

Fixes #9
parent b2cac53d
...@@ -115,6 +115,7 @@ module Paperclip ...@@ -115,6 +115,7 @@ module Paperclip
ensure_required_accessors! ensure_required_accessors!
if uploaded_file.is_a?(Paperclip::Attachment) if uploaded_file.is_a?(Paperclip::Attachment)
uploaded_filename = uploaded_file.original_filename
uploaded_file = uploaded_file.to_file(:original) uploaded_file = uploaded_file.to_file(:original)
close_uploaded_file = uploaded_file.respond_to?(:close) close_uploaded_file = uploaded_file.respond_to?(:close)
end end
...@@ -126,8 +127,9 @@ module Paperclip ...@@ -126,8 +127,9 @@ module Paperclip
return nil if uploaded_file.nil? return nil if uploaded_file.nil?
uploaded_filename ||= uploaded_file.original_filename
@queued_for_write[:original] = to_tempfile(uploaded_file) @queued_for_write[:original] = to_tempfile(uploaded_file)
instance_write(:file_name, uploaded_file.original_filename.strip) instance_write(:file_name, uploaded_filename.strip)
instance_write(:content_type, uploaded_file.content_type.to_s.strip) instance_write(:content_type, uploaded_file.content_type.to_s.strip)
instance_write(:file_size, uploaded_file.size.to_i) instance_write(:file_size, uploaded_file.size.to_i)
instance_write(:fingerprint, generate_fingerprint(uploaded_file)) instance_write(:fingerprint, generate_fingerprint(uploaded_file))
......
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