I have the following snippet:
tempfile = Tempfile.new(export_file.filename)
begin
tempfile.write(contents)
file_storage_service.store(export_file.filename, tempfile)
ensure
tempfile.close!
end
store
def store(filename, file)
client = Aws::S3::Client.new(options)
object = Aws::S3::Object.new(bucket_name, filename, client: client)
object.upload_file(file)
end
Aws::S3::Errors::BadDigest
store
close!
close
It seems that S3's upload_file
expects a file with the cursor reset. Calling tempfile.rewind
just before calling store
solves this issue.