How do I parse a CSV file located in a Amazon S3 bucket

前端 未结 3 973
-上瘾入骨i
-上瘾入骨i 2021-01-05 06:08

Below is the code I\'m using to parse the CSV from within the app, but I want to parse a file located in a Amazon S3 bucket. It needs to work when pushed to Heroku as well.

3条回答
  •  礼貌的吻别
    2021-01-05 06:17

    You can get the csv file from S3 like this:

    require 'csv'
    require 'net/http'
    
    CSV.parse(Net::HTTP.get(s3_file_url), headers: true).each do |row|
    # code for processing row here
    end
    

提交回复
热议问题