pub struct UploadPolicyBuilder { /* private fields */ }
Expand description
上传策略构建器
用于生成上传策略,一旦生成完毕,上传策略将无法被修改
Implementations§
Source§impl UploadPolicyBuilder
impl UploadPolicyBuilder
Sourcepub fn new_policy_for_bucket(
bucket: impl Into<BucketName>,
upload_token_lifetime: Duration,
) -> Self
pub fn new_policy_for_bucket( bucket: impl Into<BucketName>, upload_token_lifetime: Duration, ) -> Self
为指定的存储空间生成的上传策略
允许用户上传文件到指定的存储空间,不限制上传客户端指定对象名称。
上传策略根据给出的客户端配置指定上传凭证有效期
Sourcepub fn new_policy_for_object(
bucket: impl Into<BucketName>,
object: impl Into<ObjectName>,
upload_token_lifetime: Duration,
) -> Self
pub fn new_policy_for_object( bucket: impl Into<BucketName>, object: impl Into<ObjectName>, upload_token_lifetime: Duration, ) -> Self
为指定的存储空间和对象名称生成的上传策略
允许用户以指定的对象名称上传文件到指定的存储空间。 上传客户端不能指定与上传策略冲突的对象名称。
上传策略根据给出的客户端配置指定上传凭证有效期
Sourcepub fn new_policy_for_objects_with_prefix(
bucket: impl Into<BucketName>,
prefix: impl AsRef<str>,
upload_token_lifetime: Duration,
) -> Self
pub fn new_policy_for_objects_with_prefix( bucket: impl Into<BucketName>, prefix: impl AsRef<str>, upload_token_lifetime: Duration, ) -> Self
为指定的存储空间和对象名称前缀生成的上传策略
允许用户以指定的对象名称前缀上传文件到指定的存储空间。 上传客户端指定包含该前缀的对象名称。
上传策略根据给出的客户端配置指定上传凭证有效期
Sourcepub fn token_lifetime(&mut self, lifetime: Duration) -> &mut Self
pub fn token_lifetime(&mut self, lifetime: Duration) -> &mut Self
指定上传凭证有效期
Sourcepub fn token_deadline(&mut self, deadline: SystemTime) -> &mut Self
pub fn token_deadline(&mut self, deadline: SystemTime) -> &mut Self
指定上传凭证过期时间
Sourcepub fn insert_only(&mut self) -> &mut Self
pub fn insert_only(&mut self) -> &mut Self
仅允许创建新的对象,不允许覆盖和修改同名对象
Sourcepub fn enable_mime_detection(&mut self) -> &mut Self
pub fn enable_mime_detection(&mut self) -> &mut Self
启用 MIME 类型自动检测
Sourcepub fn disable_mime_detection(&mut self) -> &mut Self
pub fn disable_mime_detection(&mut self) -> &mut Self
禁用 MIME 类型自动检测
Sourcepub fn return_url(&mut self, url: impl Into<String>) -> &mut Self
pub fn return_url(&mut self, url: impl Into<String>) -> &mut Self
Web 端文件上传成功后,浏览器执行 303 跳转的 URL
通常用于表单上传。
文件上传成功后会跳转到 <return_url>?upload_ret=<queryString>
,
<queryString>
包含 return_body()
内容。
如不设置 return_url
,则直接将 return_body()
的内容返回给客户端
Sourcepub fn return_body(&mut self, body: impl Into<String>) -> &mut Self
pub fn return_body(&mut self, body: impl Into<String>) -> &mut Self
Sourcepub fn callback<V: AsRef<[S]>, S: AsRef<str>>(
&mut self,
urls: V,
host: impl Into<String>,
body: impl Into<String>,
body_type: impl Into<String>,
) -> &mut Self
pub fn callback<V: AsRef<[S]>, S: AsRef<str>>( &mut self, urls: V, host: impl Into<String>, body: impl Into<String>, body_type: impl Into<String>, ) -> &mut Self
Sourcepub fn file_size_limitation(&mut self, size: impl RangeBounds<u64>) -> &mut Self
pub fn file_size_limitation(&mut self, size: impl RangeBounds<u64>) -> &mut Self
限定上传文件尺寸的范围
单位为字节
Sourcepub fn mime_types<V: AsRef<[S]>, S: AsRef<str>>(
&mut self,
content_types: V,
) -> &mut Self
pub fn mime_types<V: AsRef<[S]>, S: AsRef<str>>( &mut self, content_types: V, ) -> &mut Self
限定用户上传的文件类型
指定本字段值,七牛服务器会侦测文件内容以判断 MIME 类型,再用判断值跟指定值进行匹配, 匹配成功则允许上传,匹配失败则返回 403 状态码
Sourcepub fn object_lifetime(&mut self, lifetime: Duration) -> &mut Self
pub fn object_lifetime(&mut self, lifetime: Duration) -> &mut Self
对象生命周期
精确到天
Sourcepub fn build(&self) -> UploadPolicy
pub fn build(&self) -> UploadPolicy
生成上传策略
Sourcepub fn build_token(
&self,
credential: Credential,
opts: ToStringOptions,
) -> StaticUploadTokenProvider
pub fn build_token( &self, credential: Credential, opts: ToStringOptions, ) -> StaticUploadTokenProvider
根据七牛认证信息直接生成上传凭证
Trait Implementations§
Source§impl Clone for UploadPolicyBuilder
impl Clone for UploadPolicyBuilder
Source§fn clone(&self) -> UploadPolicyBuilder
fn clone(&self) -> UploadPolicyBuilder
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for UploadPolicyBuilder
impl Debug for UploadPolicyBuilder
Source§impl From<UploadPolicy> for UploadPolicyBuilder
impl From<UploadPolicy> for UploadPolicyBuilder
Source§fn from(policy: UploadPolicy) -> Self
fn from(policy: UploadPolicy) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for UploadPolicyBuilder
impl RefUnwindSafe for UploadPolicyBuilder
impl Send for UploadPolicyBuilder
impl Sync for UploadPolicyBuilder
impl Unpin for UploadPolicyBuilder
impl UnwindSafe for UploadPolicyBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more