S3:如何在不下载完整文件的情况下进行部分读/读? [英] S3: How to do a partial read / seek without downloading the complete file?

查看:216
本文介绍了S3:如何在不下载完整文件的情况下进行部分读/读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然它们类似于文件,但是Amazon S3中的对象并不是真正的文件,就像S3存储桶不是真正的目录一样。在Unix系统上,我可以使用 head 来预览文件的前几行,无论它有多大,但我不能在S3上执行此操作。那么如何对S3进行部分阅读呢?

Although they resemble files, objects in Amazon S3 aren't really "files", just like S3 buckets aren't really directories. On a Unix system I can use head to preview the first few lines of a file, no matter how large it is, but I can't do this on a S3. So how do I do a partial read on S3?

推荐答案

S3文件可能很大,但你不需要获取整个事情就是读取前几个字节。 S3 API支持HTTP 范围:标题(参见RFC 2616),它采用字节范围参数。

S3 files can be huge, but you don't have to fetch the entire thing just to read the first few bytes. The S3 APIs support the HTTP Range: header (see RFC 2616), which take a byte range argument.

只需添加范围: bytes = 0-NN 到S3请求的标头,其中NN是要读取的请求字节数,并且您将仅获取那些字节而不是读取整个文件。现在,您可以预览在S3存储桶中保留的900 GB CSV文件,而无需等待整个内容下载。阅读完整的 GET对象 docs

Just add a Range: bytes=0-NN header to your S3 request, where NN is the requested number of bytes to read, and you'll fetch only those bytes rather than read the whole file. Now you can preview that 900 GB CSV file you left in an S3 bucket without waiting for the entire thing to download. Read the full GET Object docs on Amazon's developer docs.

这篇关于S3:如何在不下载完整文件的情况下进行部分读/读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆