Struct UploadPolicyBuilder

Source
pub struct UploadPolicyBuilder { /* private fields */ }
Expand description

上传策略构建器

用于生成上传策略,一旦生成完毕,上传策略将无法被修改

Implementations§

Source§

impl UploadPolicyBuilder

Source

pub fn new_policy_for_bucket( bucket: impl Into<BucketName>, upload_token_lifetime: Duration, ) -> Self

为指定的存储空间生成的上传策略

允许用户上传文件到指定的存储空间,不限制上传客户端指定对象名称。

上传策略根据给出的客户端配置指定上传凭证有效期

Source

pub fn new_policy_for_object( bucket: impl Into<BucketName>, object: impl Into<ObjectName>, upload_token_lifetime: Duration, ) -> Self

为指定的存储空间和对象名称生成的上传策略

允许用户以指定的对象名称上传文件到指定的存储空间。 上传客户端不能指定与上传策略冲突的对象名称。

上传策略根据给出的客户端配置指定上传凭证有效期

Source

pub fn new_policy_for_objects_with_prefix( bucket: impl Into<BucketName>, prefix: impl AsRef<str>, upload_token_lifetime: Duration, ) -> Self

为指定的存储空间和对象名称前缀生成的上传策略

允许用户以指定的对象名称前缀上传文件到指定的存储空间。 上传客户端指定包含该前缀的对象名称。

上传策略根据给出的客户端配置指定上传凭证有效期

Source

pub fn token_lifetime(&mut self, lifetime: Duration) -> &mut Self

指定上传凭证有效期

Source

pub fn token_deadline(&mut self, deadline: SystemTime) -> &mut Self

指定上传凭证过期时间

Source

pub fn insert_only(&mut self) -> &mut Self

仅允许创建新的对象,不允许覆盖和修改同名对象

Source

pub fn enable_mime_detection(&mut self) -> &mut Self

启用 MIME 类型自动检测

Source

pub fn disable_mime_detection(&mut self) -> &mut Self

禁用 MIME 类型自动检测

Source

pub fn file_type(&mut self, file_type: FileType) -> &mut Self

设置文件类型

Source

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() 的内容返回给客户端

Source

pub fn return_body(&mut self, body: impl Into<String>) -> &mut Self

上传成功后,自定义七牛云最终返回给上传端(在指定 return_url() 时是携带在跳转路径参数中)的数据

支持魔法变量自定义变量return_body 要求是合法的 JSON 文本。 例如 {"key": $(key), "hash": $(etag), "w": $(imageInfo.width), "h": $(imageInfo.height)}

Source

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

上传成功后,七牛云向业务服务器发送 POST 请求的 URL 列表,Host,回调请求的内容以及其 Content-Type

七牛服务器会在上传成功后逐一回调 URL 直到有一个成功为止

如果给出的 host 为空字符串,则使用默认的 Host

body 参数必须不能为空,支持魔法变量自定义变量 body_type 参数表示 body 参数的 Content-Type,如果为空,则为默认的 application/x-www-form-urlencoded

Source

pub fn save_as(&mut self, save_as: impl Into<String>, force: bool) -> &mut Self

自定义对象名称

支持魔法变量自定义变量forcefalse 时,save_as 字段仅当用户上传的时候没有主动指定对象名时起作用, forcetrue 时,将强制按 save_as 字段的内容命名

Source

pub fn file_size_limitation(&mut self, size: impl RangeBounds<u64>) -> &mut Self

限定上传文件尺寸的范围

单位为字节

Source

pub fn mime_types<V: AsRef<[S]>, S: AsRef<str>>( &mut self, content_types: V, ) -> &mut Self

限定用户上传的文件类型

指定本字段值,七牛服务器会侦测文件内容以判断 MIME 类型,再用判断值跟指定值进行匹配, 匹配成功则允许上传,匹配失败则返回 403 状态码

Source

pub fn object_lifetime(&mut self, lifetime: Duration) -> &mut Self

对象生命周期

精确到天

Source

pub fn set(&mut self, k: String, v: JsonValue) -> &mut Self

直接设置上传策略的键值对

Source

pub fn unset<Q>(&mut self, k: &Q) -> &mut Self
where String: Borrow<Q>, Q: ?Sized + Ord + Eq + Hash,

直接删除上传策略的键

Source

pub fn build(&self) -> UploadPolicy

生成上传策略

Source

pub fn build_token( &self, credential: Credential, opts: ToStringOptions, ) -> StaticUploadTokenProvider

根据七牛认证信息直接生成上传凭证

Source

pub fn reset(&mut self)

重置上传策略构建器

重置构建器使得构建器可以被多次复用

Trait Implementations§

Source§

impl Clone for UploadPolicyBuilder

Source§

fn clone(&self) -> UploadPolicyBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UploadPolicyBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<UploadPolicy> for UploadPolicyBuilder

Source§

fn from(policy: UploadPolicy) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.