【问题标题】:Serving large file from Google Cloud Storage in Google App Engine在 Google App Engine 中从 Google Cloud Storage 提供大文件
【发布时间】:2017-01-12 17:35:18
【问题描述】:

在 App Engine 柔性环境中运行 dart 服务器,似乎存在提供大于 32MB 的文件的限制。

对我要提供的文件有一些要求:

  • 文件大小可以大于 32MB
  • 不能公开访问(授权在服务器上完成)

目前我尝试使用gcloud 库从存储桶中读取文件,然后通过管道传输到request.response。由于限制,此操作失败,例如:HTTP response was too large: 33554744. The limit is: 33554432.

有没有办法从存储中提供更大的文件?关于这个主题的文档非常混乱(我认为根本没有 dart 特定的文档)。我一直在阅读有关 Blobstore 的内容,但我不确定此解决方案是否适用于 dart。

【问题讨论】:

  • FWIW,我认为这根本不是 Dart 特有的。 32MB 大小限制适用于所有 App Engine FE。 BlobStore 是一种选择,但看起来 Cloud Storage 成功了(cloud.google.com/appengine/docs/standard/python/blobstore,第一个注释)。您是否正在寻找类似 @​​987654325@ 但在 Dart 中的内容?
  • cloud.google.com/storage/docs/access-control/signed-urls 与此处相关吗?如果是这样,在 gcloud lib API 中包含它会对您有帮助吗?
  • @filiph 如果我可以直接从 Dart gcloud API 中做到这一点,那将非常方便。目前我使用我自己的实现,使用googleapis_auth/src/crypto/pem.dartgoogleapis_auth/src/crypto/rsa_sign.dart
  • @filiph 我们在 gcloud 存储库中为此创建了一个 issue

标签: google-app-engine dart google-cloud-storage


【解决方案1】:

正如@filiph 建议的那样,您可以使用来自 Google Cloud Storage 的signed urls

服务器端我在 python 中有这段代码:

import time
import base64

from oauth2client.service_account import ServiceAccountCredentials


def create_signed_url(file_location):
    # Get credentials
    creds = ServiceAccountCredentials.from_json_keyfile_name('filename_of_private_key.json')
    client_id = creds.service_account_email

    # Set time limit to two hours from now
    timestamp = time.time() + 2 * 3600

    # Generate signature string
    signature_string = "GET\n\n\n%d\n%s" % (timestamp, file_location)
    signature = creds.sign_blob(signature_string)[1]
    encoded_signature = base64.b64encode(signature)
    encoded_signature = encoded_signature.replace("+", "%2B").replace("/", "%2F")

    # Generate url
    return "https://storage.googleapis.com%s?GoogleAccessId=%s&Expires=%d&&Signature=%s" % (
    file_location, client_id, timestamp, encoded_signature)

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    • 2018-07-22
    • 2015-07-07
    • 1970-01-01
    相关资源
    最近更新 更多