Crates.io | qiniu-upload-token |
lib.rs | qiniu-upload-token |
version | 0.2.4 |
source | src |
created_at | 2022-04-07 06:39:00.28538 |
updated_at | 2023-12-26 07:29:33.464143 |
description | Qiniu Upload Policy Builder & Parser, Upload Token Generator & Parser for Rust |
homepage | https://www.qiniu.com |
repository | https://github.com/qiniu/rust-sdk.git |
max_upload_size | |
id | 563494 |
size | 116,997 |
负责配置七牛对象上传所需要的上传策略,并提供生成上传凭证的库函数,同时提供 UploadTokenProvider
方便扩展获取上传凭证的方式。
同时提供阻塞接口和异步接口(异步接口需要启用 async
功能)。
提供 UploadTokenProvider
的多个实现方式,例如:
StaticUploadTokenProvider
根据其他服务计算得到的上传凭证字符串生成上传凭证FromUploadPolicy
根据给出的上传策略和认证信息生成上传凭证BucketUploadTokenProvider
基于存储空间和认证信息即时生成上传凭证ObjectUploadTokenProvider
基于存储空间,对象名称和认证信息即时生成上传凭证CachedUploadTokenProvider
缓存生成的上传凭证,不必每次都即时生成[dependencies]
qiniu-upload-token = "0.2.1"
[dependencies]
qiniu-upload-token = { version = "0.2.1", features = ["async"] }
use qiniu_upload_token::{FileType, UploadPolicy, credential::Credential, prelude::*};
use std::time::Duration;
let upload_policy = UploadPolicy::new_for_object("your-bucket", "your-key", Duration::from_secs(3600))
.file_type(FileType::InfrequentAccess)
.build();
let credential = Credential::new("your-access-key", "your-secret-key");
let upload_token = upload_policy
.into_dynamic_upload_token_provider(credential)
.to_token_string(Default::default())?;
use qiniu_upload_token::{StaticUploadTokenProvider, prelude::*};
let upload_token: StaticUploadTokenProvider = "your-access-key:qRD-BSf_XGtovGsuOePTc1EKJo8=:eyJkZWFkbGluZSI6MTY0NzgyODY3NCwic2NvcGUiOiJ5b3VyLWJ1Y2tldC1uYW1lIn0=".parse()?;
let access_key = upload_token.access_key(Default::default())?;
let bucket_name = upload_token.bucket_name(Default::default())?;
let upload_policy = upload_token.policy(Default::default())?;
use qiniu_upload_token::{FileType, UploadPolicy, credential::Credential, prelude::*};
use std::time::Duration;
let upload_policy = UploadPolicy::new_for_object("your-bucket", "your-key", Duration::from_secs(3600))
.file_type(FileType::InfrequentAccess)
.build();
let credential = Credential::new("your-access-key", "your-secret-key");
let upload_token = upload_policy
.into_dynamic_upload_token_provider(credential)
.async_to_token_string(Default::default()).await?;
use qiniu_upload_token::{StaticUploadTokenProvider, prelude::*};
let upload_token: StaticUploadTokenProvider = "your-access-key:qRD-BSf_XGtovGsuOePTc1EKJo8=:eyJkZWFkbGluZSI6MTY0NzgyODY3NCwic2NvcGUiOiJ5b3VyLWJ1Y2tldC1uYW1lIn0=".parse()?;
let access_key = upload_token.async_access_key(Default::default()).await?;
let bucket_name = upload_token.async_bucket_name(Default::default()).await?;
let upload_policy = upload_token.async_policy(Default::default()).await?;
1.70.0
This project is licensed under the MIT license.