简体   繁体   English

如何检查文件是否存在于s3存储桶中

[英]How to check if a file exists into s3 bucket

I'm moving my site to Amazon S3 and Cloudfront, since these are all public resources I suppose to enable s3 website hosting. 我将网站迁移到Amazon S3和Cloudfront,因为这些都是我想启用s3网站托管的公共资源。 But I would like to understand what's best (and cheaper) way to access my files. 但是我想了解哪种是最好(和更便宜)的方式来访问我的文件。

I mean, If I would like to see if a file exist (or read it) should I do an http request to http://mybucket.s3.amaxon.com/filename or use the S3 client ? 我的意思是,如果我想查看文件是否存在(或读取文件),我应该向http://mybucket.s3.amaxon.com/filename发出http请求还是使用S3客户端?

Or even use a distribution created and configured ad-hoc for mybucket? 甚至使用为mybucket创建和配置的临时发行版?

Does anyone know if there is a cost difference between an HTTP request with HEAD method on s3 or cloudfront or S3 client? 有谁知道s3或cloudfront或S3客户端上的HEAD方法的HTTP请求之间是否存在成本差异?

I think HTTP call should be cheaper than S3 client request, but on the other hand, I cannot use authentication. 我认为HTTP调用应该比S3客户端请求便宜,但另一方面,我不能使用身份验证。 And, I suppose, the Cloudfront distribution should not enable any kind of cache. 而且,我想,Cloudfront发行版不应启用任何类型的缓存。

I'm not exactly sure what you mean by the S3 client but the most efficient way to check to see if a file exists in S3 or not is to attempt a HEAD request on the resource. 我不确定S3 client含义,但检查文件是否存在于S3中的最有效方法是尝试对资源进行HEAD请求。 There really isn't any other way so I'm sure that under the covers that's exactly what your S3 client is doing, too. 确实没有其他方法,因此我敢肯定, S3 client也在做这些事情。

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

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