Commit 9d1355b5 by Sebastien Guignot Committed by Prem Sichanugrist

Fix attachment.reprocess! when using storage providers fog and s3.

parent 02d99ec3
......@@ -30,6 +30,11 @@ module Paperclip
@tempfile.read(length, buffer)
end
# We don't use this directly, but aws/sdk does.
def rewind
@tempfile.rewind
end
def eof?
@tempfile.eof?
end
......@@ -50,7 +55,11 @@ module Paperclip
def copy_to_tempfile(src)
dest = Tempfile.new(src.original_filename)
dest.binmode
FileUtils.cp(src.path(:original), dest.path)
if src.respond_to? :copy_to_local_file
src.copy_to_local_file(:original, dest.path)
else
FileUtils.cp(src.path(:original), dest.path)
end
dest
end
......
......@@ -135,6 +135,17 @@ module Paperclip
(creds[env] || creds).symbolize_keys
end
def copy_to_local_file(style, local_dest_path)
log("copying #{path(style)} to local file #{local_dest_path}")
local_file = ::File.open(local_dest_path, 'wb')
file = directory.files.get(path(style))
local_file.write(file.body)
local_file.close
rescue Fog::Errors::Error => e
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
false
end
private
def find_credentials(creds)
......
......@@ -307,6 +307,17 @@ module Paperclip
@queued_for_delete = []
end
def copy_to_local_file(style, local_dest_path)
log("copying #{path(style)} to local file #{local_dest_path}")
local_file = ::File.open(local_dest_path, 'wb')
file = s3_object(style)
local_file.write(file.read)
local_file.close
rescue AWS::Errors::Base => e
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
false
end
def find_credentials creds
case creds
when File
......
require './test/helper'
require 'aws'
unless ENV["S3_BUCKET"].blank?
class S3LiveTest < Test::Unit::TestCase
......@@ -105,7 +104,11 @@ unless ENV["S3_BUCKET"].blank?
assert_success_response @dummy.avatar.url
end
should "be destoryable" do
should "be reprocessable" do
assert @dummy.avatar.reprocess!
end
should "be destroyable" do
url = @dummy.avatar.url
@dummy.destroy
assert_not_found_response url
......
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