Skip to content

Commit

Permalink
Merge pull request carrierwaveuploader#468 from chrisdurtschi/fog_str…
Browse files Browse the repository at this point in the history
…eaming_upload

Fog streaming upload
  • Loading branch information
bensie committed Sep 23, 2011
2 parents 2a1d3fc + 1c48854 commit ba8b9d4
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 127 deletions.
12 changes: 12 additions & 0 deletions lib/carrierwave/sanitized_file.rb
Expand Up @@ -216,6 +216,18 @@ def delete
FileUtils.rm(self.path) if exists?
end

##
# Returns a File object, or nil if it does not exist.
#
# === Returns
#
# [File] a File object representing the SanitizedFile
#
def to_file
return @file if @file.is_a?(File)
File.open(path) if exists?
end

##
# Returns the content type of the file.
#
Expand Down
3 changes: 2 additions & 1 deletion lib/carrierwave/storage/fog.rb
Expand Up @@ -225,9 +225,10 @@ def size
#
# [Boolean] true on success or raises error
def store(new_file)
fog_file = new_file.to_file
@content_type ||= new_file.content_type
@file = directory.files.create({
:body => new_file.read,
:body => fog_file ? fog_file : new_file.read,
:content_type => @content_type,
:key => path,
:public => @uploader.fog_public
Expand Down
32 changes: 32 additions & 0 deletions spec/sanitized_file_spec.rb
Expand Up @@ -383,6 +383,20 @@
File.exists?(@sanitized_file.path).should be_false
end
end

describe '#to_file' do
it "should return a File object" do
@sanitized_file.to_file.should be_a(File)
end

it "should have the same path as the SanitizedFile" do
@sanitized_file.to_file.path.should == @sanitized_file.path
end

it "should have the same contents as the SantizedFile" do
@sanitized_file.to_file.read.should == @sanitized_file.read
end
end
end

describe "with a valid Hash" do
Expand Down Expand Up @@ -470,6 +484,12 @@
end
end

describe '#to_file' do
it "should be nil" do
@sanitized_file.to_file.should be_nil
end
end

end

describe "with a valid File object" do
Expand Down Expand Up @@ -614,6 +634,12 @@
running { @empty.delete }.should_not raise_error
end
end

describe '#to_file' do
it "should be nil" do
@empty.to_file.should be_nil
end
end
end

describe "that is an empty string" do
Expand Down Expand Up @@ -680,6 +706,12 @@
running { @empty.delete }.should_not raise_error
end
end

describe '#to_file' do
it "should be nil" do
@empty.to_file.should be_nil
end
end
end

end

0 comments on commit ba8b9d4

Please sign in to comment.