简体   繁体   中英

How to save excel file to amazon s3 from python or ruby

Is it possible to create a new excel spreadsheet file and save it to an Amazon S3 bucket without first saving to a local filesystem?

For example, I have a Ruby on Rails web application which now generates Excel spreadsheets using the write_xlsx gem and saving it to the server's local file system. Internally, it looks like the gem is using Ruby's IO.copy_stream when it saves the spreadsheet. I'm not sure this will work if moving to Heroku and S3.

Has anyone done this before using Ruby or even Python?

I found this earlier question, Heroku + ephemeral filesystem + AWS S3 . So, it would seem this is not possible using Heroku. Theoretically, it would be possible using a service which allows adding an Amazon EBS .

You have dedicated Ruby Gem to help you moving file to Amazon S3:

https://rubygems.org/gems/aws-s3

If you want more details about the implementation, here is the git repository. The documentation on the page is very complete, and explain how to move file to S3. Hope it helps.

Once your xls file is created, the library helps you create a S3Objects and store it into a Bucket (which you can also create with the library).

S3Object.store('keyOfYourData', open('nameOfExcelFile.xls'), 'bucketName')

If you want more choice, Amazon also delivered an official Gem for this purpose: https://rubygems.org/gems/aws-sdk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM