Rails controller
class DownloadController < ApplicationController
include ActionController::Streaming
include Zipline
AWS_S3_REGION = "ap-northeast-1"
AWS_S3_BUCKET = "zipline-test"
def zip
zipline(s3files, "s3files.zip")
end
private
def s3files
s3 = Aws::S3::Client.new(region: AWS_S3_REGION)
files = %w(
file1.json
file2.json
file3.json
)
files.lazy.map do |file|
logger.debug "get file from s3 : #{file}"
s3_object = s3.get_object(bucket: AWS_S3_BUCKET, key: file)
[s3_object.body, file]
end
end
end
- ダウンロード対象のファイルを順次zipに固めながら chunked response としてクライアントに返す。部分が肝
References