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云存储对象的过期日期/时间_Django_Google Cloud Platform_Django Rest Framework_Google Cloud Storage - Fatal编程技术网

如何在Django中增加Google云存储对象的过期日期/时间

如何在Django中增加Google云存储对象的过期日期/时间,django,google-cloud-platform,django-rest-framework,google-cloud-storage,Django,Google Cloud Platform,Django Rest Framework,Google Cloud Storage,我有一个Django REST API,它使用storages.backends.gcloud.GoogleCloudStorage作为它的默认文件存储。我注意到,从任何API检索的媒体文件(例如用户的个人资料图片)在URL中都有一个Expires值 以下是文件的示例URL: https://storage.googleapis.com//users/a96db2f0-99a0-4691-aadb-708dc5268f77.png?Expires=1597840065&GoogleAccessI

我有一个Django REST API,它使用
storages.backends.gcloud.GoogleCloudStorage
作为它的
默认文件存储
。我注意到,从任何API检索的媒体文件(例如用户的个人资料图片)在URL中都有一个
Expires

以下是文件的示例URL:
https://storage.googleapis.com//users/a96db2f0-99a0-4691-aadb-708dc5268f77.png?Expires=1597840065&GoogleAccessId=&Signature=


如果我把它转换成一个实际的日期,它实际上是从被请求的时间算起的24小时。我如何将其增加到一个非常大的时间(例如1年)?

事实证明,他们的文档中都有说明:

GS_过期(可选:默认为timedelta(秒=86400))

生成的URL在过期之前有效的时间。默认值 是一天。公共文件将返回一个未过期的url。文件夹 将由提供给django storages的凭据签名(请参阅 GS_证书)

注意:默认的谷歌计算引擎(GCE)服务帐户无法使用 为URL签名

GS_过期值由底层Google库处理。 它支持timedelta、datetime或自历元时间起的整数秒

因此,我只需在settings.py中执行
GS\u EXPIRATION=timedelta(seconds=864000)
,这样到期时间将为10天