Skip to content

aws-sdk-s3 no longer handles downloading to a File, only a string path #3284

@DanielHeath

Description

@DanielHeath

Describe the bug

Commit b0541aa introduced the use of SecureRandom.alphanumeric to generate a path on disk.

However, this coerces the path argument to a string.

While perhaps not intentional, passing a file (or tempfile) object to FileDownloader#download previously worked roughly as you'd expect; after this change, it doesn't.

As a result, updating to the latest s3 sdk has broken previously-working software.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

o = Aws::S3::Object.new(bucket_name:, key:)
Tempfile.open("save file here", encoding: 'ascii-8bit') do |f|
  o.download_file(f)
end

File is now downloaded

Current Behavior

o = Aws::S3::Object.new(bucket_name:, key:)
Tempfile.open("save file here", encoding: 'ascii-8bit') do |f|
  o.download_file(f)
end

#<Thread:0x0000f62d63305f20 /app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:123 run> terminated with exception (report_on_exception is true):
/app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:162:in 'IO.write': No such file or directory @ rb_sysopen - #<Tempfile:/tmp/sitemapcases-12.xml20250824-78328-bknqpz>.s3tmp.GqjSEdom (Errno::ENOENT)
	from /app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:162:in 'Aws::S3::FileDownloader#write'
	from /app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:135:in 'block (2 levels) in Aws::S3::FileDownloader#download_in_threads'
#<Thread:0x0000f62d63305db8 /app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:123 run> terminated with exception (report_on_exception is true):
/app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:162:in 'IO.write': No such file or directory @ rb_sysopen - #<Tempfile:/tmp/sitemapcases-12.xml20250824-78328-bknqpz>.s3tmp.GqjSEdom (Errno::ENOENT)
	from /app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:162:in 'Aws::S3::FileDownloader#write'
	from /app/shared/bundle/ruby/3.4.0/gems/aws-sdk-s3-1.196.1/lib/aws-sdk-s3/file_downloader.rb:135:in 'block (2 levels) in Aws::S3::FileDownloader#download_in_threads'
/app/shared/bundle/ruby/3.4.0/gems/irb-1.15.2/lib/irb.rb:406:in 'full_message': No such file or directory @ rb_sysopen - #<Tempfile:/tmp/sitemapcases-12.xml20250824-78328-bknqpz>.s3tmp.GqjSEdom (Errno::ENOENT)

Reproduction Steps

o = Aws::S3::Object.new(bucket_name:, key:)
Tempfile.open("save file here", encoding: 'ascii-8bit') do |f|
  o.download_file(f)
end

Possible Solution

Either raise a useful exception if a non-string destination is passed, or explicitly handle File objects being passed

Additional Information/Context

No response

Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version

aws-sdk-s3

Environment details (Version of Ruby, OS environment)

Ruby 3.4.1, Ubuntu 22.04.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions