<i id='ForG9'><tr id='ForG9'><dt id='ForG9'><q id='ForG9'><span id='ForG9'><b id='ForG9'><form id='ForG9'><ins id='ForG9'></ins><ul id='ForG9'></ul><sub id='ForG9'></sub></form><legend id='ForG9'></legend><bdo id='ForG9'><pre id='ForG9'><center id='ForG9'></center></pre></bdo></b><th id='ForG9'></th></span></q></dt></tr></i><div id='ForG9'><tfoot id='ForG9'></tfoot><dl id='ForG9'><fieldset id='ForG9'></fieldset></dl></div>

<tfoot id='ForG9'></tfoot>
      1. <small id='ForG9'></small><noframes id='ForG9'>

        <legend id='ForG9'><style id='ForG9'><dir id='ForG9'><q id='ForG9'></q></dir></style></legend>
          <bdo id='ForG9'></bdo><ul id='ForG9'></ul>

        如何将文件从Google云存储打开到云函数

        How to open a file from google cloud storage into a cloud function(如何将文件从Google云存储打开到云函数)

        <small id='Gjof5'></small><noframes id='Gjof5'>

        <i id='Gjof5'><tr id='Gjof5'><dt id='Gjof5'><q id='Gjof5'><span id='Gjof5'><b id='Gjof5'><form id='Gjof5'><ins id='Gjof5'></ins><ul id='Gjof5'></ul><sub id='Gjof5'></sub></form><legend id='Gjof5'></legend><bdo id='Gjof5'><pre id='Gjof5'><center id='Gjof5'></center></pre></bdo></b><th id='Gjof5'></th></span></q></dt></tr></i><div id='Gjof5'><tfoot id='Gjof5'></tfoot><dl id='Gjof5'><fieldset id='Gjof5'></fieldset></dl></div>
          <tbody id='Gjof5'></tbody>
          <tfoot id='Gjof5'></tfoot>

              <bdo id='Gjof5'></bdo><ul id='Gjof5'></ul>
              • <legend id='Gjof5'><style id='Gjof5'><dir id='Gjof5'><q id='Gjof5'></q></dir></style></legend>

                1. 本文介绍了如何将文件从Google云存储打开到云函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我通常是这样将GCS文件下载到本地的:

                  storage_client = storage.Client()
                  bucket = storage_client.get_bucket('mybucket')
                  blob = bucket.blob('myBigFile.txt')
                  blob.download_to_filename('myBigFile.txt)
                  

                  我使用的文件比云函数允许的大小/内存大得多(例如,几GB到几TB),因此上面的方法不适用于这些大文件。

                  在云函数中是否有更简单的"流式处理"(参见下面的示例1)或"直接访问"(参见下面的示例2)的方式来处理GCS文件?

                  我要做的两个例子是:

                  # 1. Load it in chunks of 5GB -- "Streaming"
                  storage_client = storage.Client()
                  bucket = storage_client.get_bucket('mybucket')
                  blob = bucket.blob('myBigFile.txt')
                  while True:
                      data = blob.download_to_filename('myBigFile.txt', chunk_size=5GB)
                      do_something(data)
                      if not data: break
                  

                  或:

                  # 2. Read the data from GCS without downloading it locally -- "Direct Access"
                  storage_client = storage.Client()
                  bucket = storage_client.get_bucket('mybucket')
                  blob = bucket.blob('myBigFile.txt')
                  with blob.read_filename('myBigFile.txt') as f:
                      do_something(f)
                  

                  我不确定是否可以做到这两点,但我给出了一些如何工作的选择。似乎支持Streaming Option,但我不确定如何将其应用于上述情况。

                  推荐答案

                  可能能够使用Cloud Storage XML API实现与您的第一个示例相近的功能。

                  在云函数内实现它应该不会有问题,因为它完全基于标准HTTP请求。

                  您可能正在查找GET Object对Download an Object的请求:

                  对象的GET请求可以包括在中定义的Range标头 HTTP 1.1 RFC将返回数据的范围限制在 对象,但请注意,在certain circumstances范围中 已忽略标头。

                  HTTPRange标头似乎可用于实现您正在寻找块(但作为独立请求,而不是在流式模式下):
                  要在响应中返回的字节范围,或 已上传到云存储系统的字节范围。

                  有效值

                  任何连续的字节范围。

                  示例

                  Range: bytes=0-1999(前2000字节)

                  Range: bytes=-2000(最后2000个字节)

                  Range: bytes=2000-(从字节2000到文件结尾)

                  实施详情

                  云硬盘不处理复杂的不相交范围,但它处理复杂的不相交范围 支持简单的连续字节范围。此外,字节范围还包括 包括在内;也就是说,字节=0-999表示 文件或对象。有效且成功的请求将导致 部分内容响应代码。有关更多信息,请参阅 specification。

                  由于范围将是静电,因此您不太可能找到完全适合的范围值来使区块与存储的数据完美匹配&边框和边框。因此,您可能需要选择稍微重叠的区块,以便能够捕获本来会拆分为2个区块的数据。

                  注意:我没有尝试此操作,答案仅基于文档。

                  这篇关于如何将文件从Google云存储打开到云函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                  <i id='jR4nF'><tr id='jR4nF'><dt id='jR4nF'><q id='jR4nF'><span id='jR4nF'><b id='jR4nF'><form id='jR4nF'><ins id='jR4nF'></ins><ul id='jR4nF'></ul><sub id='jR4nF'></sub></form><legend id='jR4nF'></legend><bdo id='jR4nF'><pre id='jR4nF'><center id='jR4nF'></center></pre></bdo></b><th id='jR4nF'></th></span></q></dt></tr></i><div id='jR4nF'><tfoot id='jR4nF'></tfoot><dl id='jR4nF'><fieldset id='jR4nF'></fieldset></dl></div>
                  1. <small id='jR4nF'></small><noframes id='jR4nF'>

                      • <bdo id='jR4nF'></bdo><ul id='jR4nF'></ul>
                        <tfoot id='jR4nF'></tfoot>

                          <tbody id='jR4nF'></tbody>
                          1. <legend id='jR4nF'><style id='jR4nF'><dir id='jR4nF'><q id='jR4nF'></q></dir></style></legend>