Struct UploadPolicy

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

上传策略

可以阅读 https://developer.qiniu.com/kodo/manual/1206/put-policy 了解七牛安全机制。

§根据指定的存储空间和对象名称,生成可以用来上传低频存储类型文件的上传策略

use qiniu_upload_token::{FileType, UploadPolicy};
use std::time::Duration;

let upload_policy = UploadPolicy::new_for_object("your-bucket", "your-key", Duration::from_secs(3600))
    .file_type(FileType::InfrequentAccess)
    .build();

Implementations§

Source§

impl UploadPolicy

Source

pub fn new_for_bucket( bucket: impl Into<BucketName>, upload_token_lifetime: Duration, ) -> UploadPolicyBuilder

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

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

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

Source

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

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

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

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

Source

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

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

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

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

Source

pub fn bucket(&self) -> Option<&str>

存储空间约束

Source

pub fn key(&self) -> Option<&str>

对象名称约束或对象名称前缀约束

Source

pub fn use_prefixal_object_key(&self) -> bool

是否是对象名称前缀约束

Source

pub fn is_insert_only(&self) -> bool

是否仅允许新增对象,不允许覆盖对象

Source

pub fn mime_detection_enabled(&self) -> bool

是否启用 MIME 类型自动检测

Source

pub fn token_deadline(&self) -> Option<SystemTime>

上传凭证过期时间

Source

pub fn return_url(&self) -> Option<&str>

Web 端文件上传成功后,浏览器执行 303 跳转的 URL

Source

pub fn return_body(&self) -> Option<&str>

上传成功后,自定义七牛云最终返回给上传端的数据

Source

pub fn callback_urls(&self) -> Option<Split<'_, char>>

上传成功后,七牛云向业务服务器发送 POST 请求的 URL 列表

Source

pub fn callback_host(&self) -> Option<&str>

上传成功后,七牛云向业务服务器发送回调请求时的 Host

Source

pub fn callback_body(&self) -> Option<&str>

上传成功后,七牛云向业务服务器发送回调请求时的内容

支持魔法变量自定义变量

Source

pub fn callback_body_type(&self) -> Option<&str>

上传成功后,七牛云向业务服务器发送回调请求时的 Content-Type

默认为 application/x-www-form-urlencoded,也可设置为 application/json

Source

pub fn save_key(&self) -> Option<&str>

自定义对象名称

支持魔法变量自定义变量

Source

pub fn is_save_key_forced(&self) -> bool

是否忽略客户端指定的对象名称,强制使用自定义对象名称进行文件命名

Source

pub fn file_size_limitation(&self) -> (Option<u64>, Option<u64>)

限定上传文件尺寸的范围

返回的第一个元素为最小尺寸,第二个元素为最大尺寸,如果为 None 表示不限制,单位为字节

Source

pub fn mime_types(&self) -> Option<Split<'_, char>>

限定用户上传的文件类型

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

Source

pub fn file_type(&self) -> Option<FileType>

文件类型

Source

pub fn object_lifetime(&self) -> Option<Duration>

对象生命周期

精确到天

Source

pub fn as_json(&self) -> String

获取 JSON 格式的上传凭证

Source

pub fn from_json(json: impl AsRef<[u8]>) -> Result<UploadPolicy>

解析 JSON 格式的上传凭证

Source

pub fn get(&self, key: impl JsonValueIndex) -> Option<&JsonValue>

根据指定的上传策略字段获取相应的值

Source

pub fn keys(&self) -> JsonMapKeys<'_>

获取上传策略的字段迭代器

Source

pub fn values(&self) -> JsonMapValues<'_>

获取上传策略的字段值的迭代器

Source

pub fn into_dynamic_upload_token_provider<T: CredentialProvider + Clone>( self, credential: T, ) -> FromUploadPolicy<T>

将上传策略转换为动态上传凭证提供者的实例

该方法与 UploadPolicy::into_static_upload_token_provider 的区别在于该方法接受 CredentialProvider 实例

Source

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

将上传策略转换为静态上传凭证提供者的实例

该方法与 UploadPolicy::into_dynamic_upload_token_provider 的区别在于该方法只能接受 Credential 实例

Trait Implementations§

Source§

impl Clone for UploadPolicy

Source§

fn clone(&self) -> UploadPolicy

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 UploadPolicy

Source§

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

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

impl<'p> From<&'p UploadPolicy> for Cow<'p, UploadPolicy>

Source§

fn from(policy: &'p UploadPolicy) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a UploadPolicy> for GotUploadPolicy<'a>

Source§

fn from(policy: &'a UploadPolicy) -> Self

Converts to this type from the input type.
Source§

impl<'p> From<Cow<'p, UploadPolicy>> for UploadPolicy

Source§

fn from(policy: Cow<'p, UploadPolicy>) -> Self

Converts to this type from the input type.
Source§

impl From<GotUploadPolicy<'_>> for UploadPolicy

Source§

fn from(result: GotUploadPolicy<'_>) -> Self

Converts to this type from the input type.
Source§

impl From<UploadPolicy> for Cow<'_, UploadPolicy>

Source§

fn from(policy: UploadPolicy) -> Self

Converts to this type from the input type.
Source§

impl From<UploadPolicy> for GotUploadPolicy<'_>

Source§

fn from(policy: UploadPolicy) -> Self

Converts to this type from the input type.
Source§

impl From<UploadPolicy> for UploadPolicyBuilder

Source§

fn from(policy: UploadPolicy) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for UploadPolicy

Source§

fn eq(&self, other: &UploadPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for UploadPolicy

Source§

impl StructuralPartialEq for UploadPolicy

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.