【问题标题】:Google Storage creating signed url for multiple objects at onceGoogle Storage 一次为多个对象创建签名 URL
【发布时间】:2020-04-10 16:17:19
【问题描述】:

我已经成功地在谷歌存储中为我的图像和视频内容使用签名 URL。我的 Django API 返回 100 个 Google Storage 对象并创建 100 个签名的 url 确实需要很长时间。有没有其他方法可以更快地生成签名 URL 或一次生成多个?

class FileUploadSignedURL(APIView):
@method_decorator(login_required(login_url='/login/'))
def post(self, request):
    filename = request.POST.get('filename')
    filetype = request.POST.get('type')
    filesize = request.POST.get('size', 0)

    uuid = get_random_string(11)
    path =  '{0}-{1}/{2}/'.format(request.user, request.user.id, uuid)
    logging.info(path);

    video = Video.objects.create(title=filename,
                                 uuid=uuid,
                                 path=path,
                                 user=request.user,
                                 type=filetype,
                                 size=filesize,
                                 status="signed")
    # create the blob - the blob has to be created in order to get a signed URL
    full_path = '{0}{1}'.format(video.path, video.name)
    blob = default_storage.open(full_path, 'wb')

    signed_url = blob.blob.generate_signed_url(expiration=default_storage.expiration, method='PUT', content_type=filetype)
    logging.debug(signed_url);

    logging.debug("FileUploadSignedURL(APIView) end")
    return Response({"uuid":video.uuid, "title": video.title, "signed_url":signed_url})

【问题讨论】:

  • 你能分享你的代码吗?请记住,它还取决于网络的吞吐量。
  • 嗨@Mario,我已经用代码更新了问题。无论是从开发环境生成的请求还是从 Google App Engine 生成的请求都需要很长时间。这里的策略是什么?在这种情况下,“实现自定义签名网址生成器”会是一种解决方案吗?

标签: django google-cloud-platform google-cloud-storage signed-url


【解决方案1】:

我的建议是将性能与基本示例进行比较:

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/cloud-client/storage_generate_signed_url_v4.py

您能否为此尝试创建一个新的服务帐户?

【讨论】:

  • 我会在这里尝试和评论。
猜你喜欢
  • 2019-12-13
  • 1970-01-01
  • 2014-01-12
  • 2014-09-04
  • 1970-01-01
  • 2020-10-07
  • 2015-08-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多