R
R
Roman Mirilaczvili2017-05-11 13:23:31
ruby
Roman Mirilaczvili, 2017-05-11 13:23:31

How to block-by-block upload a large file to S3 in Ruby, having previously encoded it in Base64?

You need to upload a large media file (more than available RAM) to S3 storage, having previously encoded it in Base64.
Help optimize your Ruby code so that reading a file, Base64 encoding, and then uploading to S3 is done block by block.

blob = StringIO.new( Base64.encode64( IO.binread('big_file.mp4')), 'rb' )
      ...
      @client.put_object(
        bucket: @s3_bucket.name,
        key: target_name,
        body: blob,
        acl: 'public-read'
      )

The Base64.encode64 documentation does not provide a way to process a file stream block by block. Are there any tricks?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question