Upload CSV stream from Ruby to S3

前端 未结 3 646
陌清茗
陌清茗 2021-02-13 20:56

I am dealing with potentially huge CSV files which I want to export from my Rails app, and since it runs on Heroku, my idea was to stream these CSV files directly to S3 when gen

3条回答
  •  春和景丽
    2021-02-13 20:57

    I would have a look at http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html#write-instance_method as that might be what you're looking for.

    EDIT http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpRuby.html might be more relevant as the first link points to ruby aws-sdk v1

    require 'aws-sdk'
    
    s3 = Aws::S3::Resource.new(region:'us-west-2')
    obj = s3.bucket('bucket-name').object('key')
    
    # string data
    obj.put(body: 'Hello World!')
    
    # IO object
    File.open('source', 'rb') do |file|
      obj.put(body: file)
    end
    

提交回复
热议问题