直接上传到 S3 还是通过 EC2?
我想为 iPhone 应用程序构建一个 Web 服务。至于文件上传,我想知道标准程序和最具成本效益的解决方案是什么。据我所知,有两种可能性:
- “客户端”>“客户端”。 S3:我直接将文件从 iPhone 上传到 S3(使用 AWS SDK
- ) EC2> S3:我将文件上传到我的服务器(运行 Django 的 EC2),然后服务器将文件上传到 S3(详见此 post)
我不打算以任何方式修改该文件。我只需要告诉数据库添加一个条目。因此,如果我要上传文件 Client > S3,无论如何我都需要连接到服务器才能进行数据库输入。
看起来 EC2 >只要两者在同一区域,S3 就不需要任何费用。
在开始实现文件上传之前,我有兴趣了解其优点和缺点。
I would like to build a web service for an iPhone app. As for file uploads, I'm wondering what the standard procedure and most cost-effective solution is. As far as I can see, there are two possibilities:
- Client > S3: I upload a file from the iPhone to S3 directly (with the AWS SDK)
- Client > EC2 > S3: I upload a file to my server (EC2 running Django) and then the server uploads the file to S3 (as detailed in this post)
I'm not planning on modifying the file in any way. I only need to tell the database to add an entry. So if I were to upload a file Client > S3, I'd need to connect to the server anyways in order to do the database entry.
It seems as if EC2 > S3 doesn't cost anything as long as the two are in the same region.
I'd be interested to hear what the advantages and disadvantages are before I start implementing file uploads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出于可扩展性的原因,我肯定会通过 S3 来实现。诚然,S3 和 EC2 之间的数据速度快且成本低,但上传需要长时间运行,与正常的 Web 请求不同。因此,您的 EC2 实例上的 NIC 可能会饱和。
相反,将 GUID 返回给客户端,上传到 S3,并将密钥设置为 GUID,并适当设置 Content-Type。然后在上传完成后调用 Web 服务/Ajax 端点以使用 GUID 密钥创建数据库记录。
I would definitely do it through S3 for scalability reasons. True, data between S3 and EC2 is fast and cheap, but uploads are long running, not like normal web requests. Therefore you may saturate the NIC on your EC2 instance.
Rather, return a GUID to the client, upload to S3 with the key set to the GUID and Content-Type set appropriately. Then call a web service/Ajax endpoint to create a DB record with the GUID key after the upload completes.