Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django Google Storage一次为多个对象创建签名url_Django_Google Cloud Platform_Google Cloud Storage_Signed Url - Fatal编程技术网

Django Google Storage一次为多个对象创建签名url

Django Google Storage一次为多个对象创建签名url,django,google-cloud-platform,google-cloud-storage,signed-url,Django,Google Cloud Platform,Google Cloud Storage,Signed Url,我已经成功地在谷歌存储中为我的图像和视频内容使用了签名URL。我的DjangoAPI返回100个Google存储对象,创建100个签名URL需要很长时间。有没有其他方法可以更快或一次生成多个签名URL class FileUploadSignedURL(APIView): @method_decorator(login_required(login_url='/login/')) def post(self, request): filename = request.POST.get('

我已经成功地在谷歌存储中为我的图像和视频内容使用了签名URL。我的DjangoAPI返回100个Google存储对象,创建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,我已经用代码更新了这个问题。无论是从开发环境还是从谷歌应用引擎生成的请求,都需要很长时间。这里的策略是什么?在这种情况下,“实现一个自定义签名的Url生成器”是一个解决方案吗?我将尝试在这里发表评论。