Google Drive PHP API - 如何流式传输大文件 [英] Google Drive PHP API - How to stream a large file

查看:161
本文介绍了Google Drive PHP API - 如何流式传输大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何一次下载所有文件,如本页示例所示: Google Drive API -Files:get 。然而,如果我有一个非常大的文件,将它全部加载到内存中将是低效率和资源占用。因此,我想知道是否可以使用Drive API对文件进行流式处理,一次只将文件的各个位加载到内存中,然后对其进行处理(以某种方式写入文件或直接写入输出)。我已经阅读了文档,甚至看了一下PHP Google Drive SDK的源代码,似乎支持流式传输,但我无法弄清楚如何使用它。所有帮助表示感谢。

解决方案

是的,可以通过将文件分成多块来指定文件大小一次。但我不确定你是否可以在完全下载之前阅读文件中的内容。



Google驱动器SDK下载文件 - 部分下载 $ b


部分下载

 部分下载涉及仅下载文件的指定部分。您
可以通过使用Range标头的字节范围
来指定要下载的文件的部分。例如:
范围:bytes = 500-999


我对 php客户端库进行了快速扫描,我不确定它支持它。这可能需要添加到客户端库或者它的东西,你将不得不使用客户端lib自己编码。


I know how to download files all at once, as shown in the example on this page: Google Drive API -Files: get.

However, if I have a very large file, loading it all into memory would be inefficient and resource-hogging. Therefore, I would like to know if it's possible to stream files with the Drive API, only loading bits of the file into memory at a time, and processing them (in some way like writing to a file or writing directly to output). I've read the docs and even looked a bit at the source for the PHP Google Drive SDK, and it seems that there is support for streaming, but I can't figure out how to use it. All help is appreciated.

解决方案

Yes it is possible to specify how much of the file to get there by getting it a chunk at a time. But i'm not sure if you can actually read what is in the file until its fully downloaded.

Google drive SDK download files - Partial download

Partial download

Partial download involves downloading only a specified portion of a file. You 
can specify the portion of the file you want to download by using a byte range 
with the Range header. For example:
Range: bytes=500-999

I did a quick scan of the php client lib and I'm not sure that it supports it. This may be something that needs to be added to the client lib or its something that you will have to code on your own with out using the client lib.

这篇关于Google Drive PHP API - 如何流式传输大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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