I have a CSV file stored on my S3 bucket, I would like to add a method in Rails so users can click on a button and download the file. In the controller I put the following
def s3_downloader(bucketName, key, localPath)
# (1) Create S3 object
s3 = Aws::S3::Resource.new(region: 'us-east-2')
# (2) Create the source object
sourceObj = s3.bucket(bucketName).object(key)
# (3) Download the file
sourceObj.get(response_target: localPath)
puts "s3://#{bucketName}/#{key} has been downloaded to #{localPath}"
end
Which I got from Tutorial
What should I put as localPath please? I tried something as simple as :
s3_downloader(Rails.application.secrets.s3_bucket_name, "Product_csv_file_sample.csv", "/Downloads")
But I get the error:
Errno::EACCES (Permission denied @ rb_sysopen - /Downloads)
2.6.3 :040 > s3_downloader(Rails.application.secrets.s3_bucket_name, "Product_csv_file_sample.csv", "/Downloads")
Traceback (most recent call last):
3: from (irb):40
2: from (irb):40:in `rescue in irb_binding'
1: from (irb):30:in `s3_downloader'
Also, how do I make sure that whether the user is on Mac or Windows, the localPath still works.
chmod 'chown' in the downlaods folder returns:
usage: chmod [-fhv] [-R [-H | -L | -P]] [-a | +a | =a [i][# [ n]]] mode|entry file ...
chmod [-fhv] [-R [-H | -L | -P]] [-E | -C | -N | -i | -I] file ...