Google云存储-如何限制用户上传的大小? [英] Google cloud storage - how to limit size of user uploads?

查看:269
本文介绍了Google云存储-如何限制用户上传的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个用户可以上传图像的服务.我想防止用户上传大于5mb的文件.

现在,我为云存储用户PUT和GET请求创建一个签名的url".有什么办法可以限制用户上传的大小?

我不希望用户错误或出于恶意目的开始上传超大文件.

解决方案

有三种方法来控制对Google Cloud Storage存储桶和对象的访问:

访问控制列表(ACL) ,它提供一种为指定的Google帐户和组指定读写访问权限的方法.

签名URL (查询字符串身份验证),该方法可为拥有URL的任何人提供有时间限制的读写访问权限,无论他们是否拥有Google帐户.

签名的政策文档 ,它提供了一种方法来指定可以上传到存储桶的内容.与签署的URL相比,政策文件对大小,内容类型和其他上传特征的控制更大,可以被网站所有者用来允许访问者将文件上传到Google Cloud Storage.

在这种情况下,您将需要使用签署的策略文档"访问控制方法.看看这篇 POST对象文章 ,并以 案例 为例. >

I'm building a service where users can upload images. I want to prevent users from uploading files bigger than 5mb.

Right now I create a 'signed url' for cloud storage user PUT and GET requests. Is there any way I can limit the size of a user upload?

I don't want users to start uploading extremely large files by mistake or with malicious intent.

解决方案

There are three ways to control access to Google Cloud Storage buckets and objects:

Access Control Lists (ACLs), which provide a way to specify read or write access for specified Google accounts and groups.

Signed URLs (Query String Authentication), which provide a way to give time-limited read or write access to anyone in possession of the URL, regardless of whether they have a Google account or not.

Signed Policy Documents, which provide a way to specify what can be uploaded to a bucket. Policy documents allow greater control over size, content type, and other upload characteristics than signed URLs, and can be used by website owners to allow visitors to upload files to Google Cloud Storage.

In this case, you'll need to use the Signed Policy Documents access control method. Take a look at this POST Object article and this case for examples.

这篇关于Google云存储-如何限制用户上传的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆