简体   繁体   English

用Django / python在Amazon s3中转换文件的最佳方法是什么?

[英]What is the best way to convert a file in amazon s3 with Django/python?

I am making a website to get to know aws and Django better. 我正在制作一个网站,以更好地了解aws和Django。 The idea is to let a user upload an excel file, convert it to csv and then let the user download the converted csv file. 这个想法是让用户上传一个excel文件,将其转换为csv,然后让用户下载转换后的csv文件。

I am using amazon s3 for file storage. 我正在使用Amazon S3进行文件存储。 My question is, what is the best way to make the conversion? 我的问题是,进行转换的最佳方法是什么? Is there any way to access the excel file once it is stored in the s3 bucket and convert it to csv via Django? 一旦将excel文件存储在s3存储桶中并通过Django将其转换为csv,是否有任何方法可以访问它? Sorry if my question is silly but I haven't been able to find much information on that online. 抱歉,如果我的问题很愚蠢,但我无法在网上找到太多信息。 Thanks in advance 提前致谢

AWS Lambda is the best way. AWS Lambda是最好的方法。 It has many types of Event triggers . 它具有许多类型的事件触发器 You can specify the bucket and the event(put, delete, copy, etc). 您可以指定存储区和事件(放置,删除,复制等)。

So what you have to do is, create a lambda function which will be triggered only when an object gets inserted into the S3 bucket. 因此,您要做的就是创建一个lambda函数,该函数仅在将对象插入S3存储桶时才触发。 In that lambda function you can do your coding such as getting the file from the S3 bucket and the conversion. 在该lambda函数中,您可以进行编码,例如从S3存储桶获取文件并进行转换。

Since you are familiar with python already, I suggest to use Boto 3 to get files from the S3 bucket 由于您已经熟悉python,因此建议您使用Boto 3从S3存储桶中获取文件

在此处输入图片说明

Check out my blog about AWS lambda with s3 if you want to get a more clearer idea and more about permissions when work with S3 bucket. 如果您想获得更清晰的主意以及有关使用S3存储桶时的权限的更多信息,请查看我的有关s3的AWS lambda的博客。

My Blog 我的博客

在Bucket的每个put事件中,您都可以触发一个AWS Lambda函数,该函数将转换您的File格式并保存在所需的Bucket位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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