#qiniu #storage #upload #token #policy #generator #builder

qiniu-upload-token

Qiniu Upload Policy Builder & Parser, Upload Token Generator & Parser for Rust

10 releases

0.2.4 Dec 26, 2023
0.2.3 May 23, 2023
0.2.2 Dec 23, 2022
0.2.1 Nov 1, 2022
0.1.2 Jun 9, 2022

#138 in Authentication

Download history 246/week @ 2024-02-26 23/week @ 2024-03-04 23/week @ 2024-03-11 11/week @ 2024-03-18 18/week @ 2024-03-25 68/week @ 2024-04-01 26/week @ 2024-04-08 17/week @ 2024-04-15 25/week @ 2024-04-22 24/week @ 2024-04-29 26/week @ 2024-05-06 28/week @ 2024-05-13 41/week @ 2024-05-20 42/week @ 2024-05-27 26/week @ 2024-06-03 33/week @ 2024-06-10

147 downloads per month
Used in 6 crates (3 directly)

MIT license

180KB
3.5K SLoC

Qiniu-Upload-Token

qiniu-upload-token docs.rs Run Test Cases GitHub release MIT licensed

概览

负责配置七牛对象上传所需要的上传策略,并提供生成上传凭证的库函数,同时提供 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?;

最低支持的 Rust 版本(MSRV)

1.70.0

联系我们

  • 如果需要帮助,请提交工单(在portal右侧点击咨询和建议提交工单,或者直接向 support@qiniu.com 发送邮件)
  • 如果有什么问题,可以到问答社区提问,问答社区
  • 更详细的文档,见官方文档站
  • 如果发现了bug, 欢迎提交 Issue
  • 如果有功能需求,欢迎提交 Issue
  • 如果要提交代码,欢迎提交 Pull Request
  • 欢迎关注我们的微信 微博,及时获取动态信息。

代码许可

This project is licensed under the MIT license.

Dependencies

~2–3MB
~66K SLoC