Use URI.open to assign external cached attachments
We were having issues with cached attachments and external services. A `Tempfile` is returned by `URI.open` when using S3, so we're dealing with this case as well.
This commit is contained in:
committed by
Javi Martín
parent
b5026e12a7
commit
5a4921a1af
@@ -37,7 +37,7 @@ module Attachable
|
||||
if Paperclip::Attachment.default_options[:storage] == :filesystem
|
||||
File.open(cached_attachment) { |file| self.attachment = file }
|
||||
else
|
||||
self.attachment = URI.parse(cached_attachment)
|
||||
self.attachment = URI.open(cached_attachment)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ module HasAttachment
|
||||
alias_method :"paperclip_#{attribute}=", :"#{attribute}="
|
||||
|
||||
define_method :"#{attribute}=" do |file|
|
||||
if file.is_a?(IO)
|
||||
if file.is_a?(IO) || file.is_a?(Tempfile) && !file.is_a?(Ckeditor::Http::QqFile)
|
||||
send(:"storage_#{attribute}").attach(io: file, filename: File.basename(file.path))
|
||||
elsif file.nil?
|
||||
send(:"storage_#{attribute}").detach
|
||||
|
||||
Reference in New Issue
Block a user