I'm looking for a programmatic way to download images from an S3 bucket to my computer.
I tried "Using send_file to download a file from Amazon S3?" but it just redirected me to a link that only shows my PDF object.
This is my download function using the AWS documentation:
s3 = Aws::S3::Resource.new(region: 'us-east-2')
obj = s3.bucket('bucket').object('image')
obj.get(response_target: '~/')
and this is my download code from linked:
data = open("https://#{bucket}.s3.amazonaws.com/#{filepath}")
send_data data.read, filename: "file.pdf", type: "application/pdf", disposition: 'inline', stream: 'true', buffer_size: '4096'
obj.get
is what is confusing: I want to download it to my computer, not my codebase.
Some say that a download link is just the image link from my bucket if it is set to public, which it is. What's this about?
Final solution: Change the disposition to 'attachment'
data = open("https://#{bucket}.s3.amazonaws.com/#{filepath}")
send_data data.read, filename: "file.pdf", type: "application/pdf", disposition: 'attachment', stream: 'true', buffer_size: '4096'