Skip to content

Commit

Permalink
Adds fix for content-lenght value missing for files uploaded via Acti…
Browse files Browse the repository at this point in the history
…onDispatch:Http::UploadedFile
  • Loading branch information
hectorcorrea committed Dec 1, 2014
1 parent e9d12ca commit 0f479d6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/active_fedora/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ def save(*)
payload = behaves_like_io?(content) ? content.read : content
headers = { 'Content-Type' => mime_type }
headers['Content-Disposition'] = "attachment; filename=\"#{@original_name}\"" if @original_name
# Setting the content-lenght is required until we figure out why Faraday
# is not doing this automatically for files uploaded via ActionDispatch.
headers['Content-Length'] = payload.size.to_s if payload.class.name == "ActionDispatch::Http::UploadedFile"
ldp_source.content = payload
if new_record?
ldp_source.create do |req|
Expand Down
30 changes: 30 additions & 0 deletions spec/integration/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
end
end

context "stand alone operation with UploadedFile" do

before(:all) do
module ActionDispatch
module Http
class UploadedFile
def initialize
@content = StringIO.new("hello world")
end
def bytesize
16
end
def read(a, b)
return @content.read(a, b)
end
def size
@content.length
end
end
end
end
end

it "should save" do
subject.content = ActionDispatch::Http::UploadedFile.new
subject.save
expect(subject).not_to be_new_record
end
end

context "when autocreate is true" do
before(:all) do
class MockAFBase < ActiveFedora::Base
Expand Down

0 comments on commit 0f479d6

Please sign in to comment.