Struct qiniu_upload_token::UploadPolicyBuilder
source · 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
为指定的存储空间生成的上传策略
允许用户上传文件到指定的存储空间,不限制上传客户端指定对象名称。
上传策略根据给出的客户端配置指定上传凭证有效期
Examples found in repository?
More examples
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
为指定的存储空间和对象名称生成的上传策略
允许用户以指定的对象名称上传文件到指定的存储空间。 上传客户端不能指定与上传策略冲突的对象名称。
上传策略根据给出的客户端配置指定上传凭证有效期
Examples found in repository?
More examples
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
指定上传凭证有效期
Examples found in repository?
src/upload_policy.rs (line 314)
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
pub fn new_policy_for_bucket(bucket: impl Into<BucketName>, upload_token_lifetime: Duration) -> Self {
let mut policy = Self {
inner: json!({
SCOPE_KEY: bucket.into().to_string(),
}),
};
policy.token_lifetime(upload_token_lifetime);
policy
}
/// 为指定的存储空间和对象名称生成的上传策略
///
/// 允许用户以指定的对象名称上传文件到指定的存储空间。
/// 上传客户端不能指定与上传策略冲突的对象名称。
///
/// 上传策略根据给出的客户端配置指定上传凭证有效期
pub fn new_policy_for_object(
bucket: impl Into<BucketName>,
object: impl Into<ObjectName>,
upload_token_lifetime: Duration,
) -> Self {
let mut policy = Self {
inner: json!({
SCOPE_KEY: bucket.into().to_string() + ":" + object.into().as_str(),
}),
};
policy.token_lifetime(upload_token_lifetime);
policy
}
/// 为指定的存储空间和对象名称前缀生成的上传策略
///
/// 允许用户以指定的对象名称前缀上传文件到指定的存储空间。
/// 上传客户端指定包含该前缀的对象名称。
///
/// 上传策略根据给出的客户端配置指定上传凭证有效期
pub fn new_policy_for_objects_with_prefix(
bucket: impl Into<BucketName>,
prefix: impl AsRef<str>,
upload_token_lifetime: Duration,
) -> Self {
let mut policy = Self {
inner: json!({
SCOPE_KEY: bucket.into().to_string() + ":" + prefix.as_ref(),
IS_PREFIXAL_SCOPE_KEY: 1,
}),
};
policy.token_lifetime(upload_token_lifetime);
policy
}
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 set(&mut self, k: String, v: JsonValue) -> &mut Self
pub fn set(&mut self, k: String, v: JsonValue) -> &mut Self
直接设置上传策略的键值对
Examples found in repository?
src/upload_policy.rs (lines 361-371)
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
pub fn token_lifetime(&mut self, lifetime: Duration) -> &mut Self {
self.set(
DEADLINE_KEY.into(),
JsonValue::Number(
SystemTime::now()
.checked_add(lifetime)
.and_then(|t| t.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|t| t.as_secs())
.unwrap_or(u64::max_value())
.into(),
),
)
}
/// 指定上传凭证过期时间
pub fn token_deadline(&mut self, deadline: SystemTime) -> &mut Self {
self.set(
DEADLINE_KEY.into(),
JsonValue::Number(
deadline
.duration_since(SystemTime::UNIX_EPOCH)
.ok()
.map(|t| t.as_secs())
.unwrap_or(u64::max_value())
.into(),
),
)
}
/// 仅允许创建新的对象,不允许覆盖和修改同名对象
pub fn insert_only(&mut self) -> &mut Self {
self.set(INSERT_ONLY_KEY.into(), JsonValue::Number(1.into()))
}
/// 启用 MIME 类型自动检测
pub fn enable_mime_detection(&mut self) -> &mut Self {
self.set(DETECT_MIME_KEY.into(), JsonValue::Number(1.into()))
}
/// 禁用 MIME 类型自动检测
pub fn disable_mime_detection(&mut self) -> &mut Self {
self.unset(DETECT_MIME_KEY)
}
/// 设置文件类型
pub fn file_type(&mut self, file_type: FileType) -> &mut Self {
self.set(FILE_TYPE_KEY.into(), JsonValue::Number(u8::from(file_type).into()))
}
/// Web 端文件上传成功后,浏览器执行 303 跳转的 URL
///
/// 通常用于表单上传。
/// 文件上传成功后会跳转到 `<return_url>?upload_ret=<queryString>`,
/// `<queryString>` 包含 `return_body()` 内容。
/// 如不设置 `return_url`,则直接将 `return_body()` 的内容返回给客户端
pub fn return_url(&mut self, url: impl Into<String>) -> &mut Self {
self.set(RETURN_URL_KEY.into(), JsonValue::String(url.into()))
}
/// 上传成功后,自定义七牛云最终返回给上传端(在指定 `return_url()` 时是携带在跳转路径参数中)的数据
///
/// 支持[魔法变量](https://developer.qiniu.com/kodo/manual/1235/vars#magicvar)和[自定义变量](https://developer.qiniu.com/kodo/manual/1235/vars#xvar)。
/// `return_body` 要求是合法的 JSON 文本。
/// 例如 `{"key": $(key), "hash": $(etag), "w": $(imageInfo.width), "h": $(imageInfo.height)}`
pub fn return_body(&mut self, body: impl Into<String>) -> &mut Self {
self.set(RETURN_BODY_KEY.into(), JsonValue::String(body.into()))
}
/// 上传成功后,七牛云向业务服务器发送 POST 请求的 URL 列表,`Host`,回调请求的内容以及其 `Content-Type`
///
/// 七牛服务器会在上传成功后逐一回调 URL 直到有一个成功为止
///
/// 如果给出的 `host` 为空字符串,则使用默认的 `Host`
///
/// `body` 参数必须不能为空,支持[魔法变量](https://developer.qiniu.com/kodo/manual/1235/vars#magicvar)和[自定义变量](https://developer.qiniu.com/kodo/manual/1235/vars#xvar)
//
/// `body_type` 参数表示 `body` 参数的 `Content-Type`,如果为空,则为默认的 `application/x-www-form-urlencoded`
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 {
self.set(CALLBACK_URL_KEY.into(), JsonValue::String(join_str_slice(urls, ";")));
{
let callback_host = host.into();
if callback_host.is_empty() {
self.unset(CALLBACK_HOST_KEY);
} else {
self.set(CALLBACK_HOST_KEY.into(), JsonValue::String(callback_host));
}
}
self.set(CALLBACK_BODY_KEY.into(), JsonValue::String(body.into()));
{
let callback_body_type = body_type.into();
if callback_body_type.is_empty() {
self.unset(CALLBACK_BODY_TYPE_KEY);
} else {
self.set(CALLBACK_BODY_TYPE_KEY.into(), JsonValue::String(callback_body_type));
}
}
self
}
/// 自定义对象名称
///
/// 支持[魔法变量](https://developer.qiniu.com/kodo/manual/1235/vars#magicvar)和[自定义变量](https://developer.qiniu.com/kodo/manual/1235/vars#xvar)。
/// `force` 为 `false` 时,`save_as` 字段仅当用户上传的时候没有主动指定对象名时起作用,
/// `force` 为 `true` 时,将强制按 `save_as` 字段的内容命名
pub fn save_as(&mut self, save_as: impl Into<String>, force: bool) -> &mut Self {
self.set(SAVE_KEY_KEY.into(), JsonValue::String(save_as.into()));
if force {
self.set(FORCE_SAVE_KEY_KEY.into(), JsonValue::Bool(true));
} else {
self.unset(FORCE_SAVE_KEY_KEY);
}
self
}
/// 限定上传文件尺寸的范围
///
/// 单位为字节
pub fn file_size_limitation(&mut self, size: impl RangeBounds<u64>) -> &mut Self {
match size.start_bound() {
Bound::Included(&s) => {
self.set(FSIZE_MIN_KEY.into(), JsonValue::Number(s.into()));
}
Bound::Excluded(&s) => {
self.set(FSIZE_MIN_KEY.into(), JsonValue::Number((s + 1).into()));
}
Bound::Unbounded => {
self.unset(FSIZE_MIN_KEY);
}
}
match size.end_bound() {
Bound::Included(&s) => {
self.set(FSIZE_LIMIT_KEY.into(), JsonValue::Number(s.into()));
}
Bound::Excluded(&s) => {
self.set(FSIZE_LIMIT_KEY.into(), JsonValue::Number((s - 1).into()));
}
Bound::Unbounded => {
self.unset(FSIZE_LIMIT_KEY);
}
}
self
}
/// 限定用户上传的文件类型
///
/// 指定本字段值,七牛服务器会侦测文件内容以判断 MIME 类型,再用判断值跟指定值进行匹配,
/// 匹配成功则允许上传,匹配失败则返回 403 状态码
pub fn mime_types<V: AsRef<[S]>, S: AsRef<str>>(&mut self, content_types: V) -> &mut Self {
self.set(
MIME_LIMIT_KEY.into(),
JsonValue::String(join_str_slice(content_types, ";")),
)
}
/// 对象生命周期
///
/// 精确到天
pub fn object_lifetime(&mut self, lifetime: Duration) -> &mut Self {
let lifetime_secs = lifetime.as_secs();
let secs_one_day = 60 * 60 * 24;
self.set(
DELETE_AFTER_DAYS_KEY.into(),
lifetime_secs
.checked_add(secs_one_day)
.and_then(|s| s.checked_sub(1))
.and_then(|s| s.checked_div(secs_one_day))
.and_then(|s| s.try_into().ok())
.unwrap_or_else(|| JsonValue::Number(u64::max_value().into())),
)
}
sourcepub fn unset<Q>(&mut self, k: &Q) -> &mut Selfwhere
String: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
pub fn unset<Q>(&mut self, k: &Q) -> &mut Selfwhere
String: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
直接删除上传策略的键
Examples found in repository?
src/upload_policy.rs (line 401)
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
pub fn disable_mime_detection(&mut self) -> &mut Self {
self.unset(DETECT_MIME_KEY)
}
/// 设置文件类型
pub fn file_type(&mut self, file_type: FileType) -> &mut Self {
self.set(FILE_TYPE_KEY.into(), JsonValue::Number(u8::from(file_type).into()))
}
/// Web 端文件上传成功后,浏览器执行 303 跳转的 URL
///
/// 通常用于表单上传。
/// 文件上传成功后会跳转到 `<return_url>?upload_ret=<queryString>`,
/// `<queryString>` 包含 `return_body()` 内容。
/// 如不设置 `return_url`,则直接将 `return_body()` 的内容返回给客户端
pub fn return_url(&mut self, url: impl Into<String>) -> &mut Self {
self.set(RETURN_URL_KEY.into(), JsonValue::String(url.into()))
}
/// 上传成功后,自定义七牛云最终返回给上传端(在指定 `return_url()` 时是携带在跳转路径参数中)的数据
///
/// 支持[魔法变量](https://developer.qiniu.com/kodo/manual/1235/vars#magicvar)和[自定义变量](https://developer.qiniu.com/kodo/manual/1235/vars#xvar)。
/// `return_body` 要求是合法的 JSON 文本。
/// 例如 `{"key": $(key), "hash": $(etag), "w": $(imageInfo.width), "h": $(imageInfo.height)}`
pub fn return_body(&mut self, body: impl Into<String>) -> &mut Self {
self.set(RETURN_BODY_KEY.into(), JsonValue::String(body.into()))
}
/// 上传成功后,七牛云向业务服务器发送 POST 请求的 URL 列表,`Host`,回调请求的内容以及其 `Content-Type`
///
/// 七牛服务器会在上传成功后逐一回调 URL 直到有一个成功为止
///
/// 如果给出的 `host` 为空字符串,则使用默认的 `Host`
///
/// `body` 参数必须不能为空,支持[魔法变量](https://developer.qiniu.com/kodo/manual/1235/vars#magicvar)和[自定义变量](https://developer.qiniu.com/kodo/manual/1235/vars#xvar)
//
/// `body_type` 参数表示 `body` 参数的 `Content-Type`,如果为空,则为默认的 `application/x-www-form-urlencoded`
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 {
self.set(CALLBACK_URL_KEY.into(), JsonValue::String(join_str_slice(urls, ";")));
{
let callback_host = host.into();
if callback_host.is_empty() {
self.unset(CALLBACK_HOST_KEY);
} else {
self.set(CALLBACK_HOST_KEY.into(), JsonValue::String(callback_host));
}
}
self.set(CALLBACK_BODY_KEY.into(), JsonValue::String(body.into()));
{
let callback_body_type = body_type.into();
if callback_body_type.is_empty() {
self.unset(CALLBACK_BODY_TYPE_KEY);
} else {
self.set(CALLBACK_BODY_TYPE_KEY.into(), JsonValue::String(callback_body_type));
}
}
self
}
/// 自定义对象名称
///
/// 支持[魔法变量](https://developer.qiniu.com/kodo/manual/1235/vars#magicvar)和[自定义变量](https://developer.qiniu.com/kodo/manual/1235/vars#xvar)。
/// `force` 为 `false` 时,`save_as` 字段仅当用户上传的时候没有主动指定对象名时起作用,
/// `force` 为 `true` 时,将强制按 `save_as` 字段的内容命名
pub fn save_as(&mut self, save_as: impl Into<String>, force: bool) -> &mut Self {
self.set(SAVE_KEY_KEY.into(), JsonValue::String(save_as.into()));
if force {
self.set(FORCE_SAVE_KEY_KEY.into(), JsonValue::Bool(true));
} else {
self.unset(FORCE_SAVE_KEY_KEY);
}
self
}
/// 限定上传文件尺寸的范围
///
/// 单位为字节
pub fn file_size_limitation(&mut self, size: impl RangeBounds<u64>) -> &mut Self {
match size.start_bound() {
Bound::Included(&s) => {
self.set(FSIZE_MIN_KEY.into(), JsonValue::Number(s.into()));
}
Bound::Excluded(&s) => {
self.set(FSIZE_MIN_KEY.into(), JsonValue::Number((s + 1).into()));
}
Bound::Unbounded => {
self.unset(FSIZE_MIN_KEY);
}
}
match size.end_bound() {
Bound::Included(&s) => {
self.set(FSIZE_LIMIT_KEY.into(), JsonValue::Number(s.into()));
}
Bound::Excluded(&s) => {
self.set(FSIZE_LIMIT_KEY.into(), JsonValue::Number((s - 1).into()));
}
Bound::Unbounded => {
self.unset(FSIZE_LIMIT_KEY);
}
}
self
}
sourcepub fn build(&self) -> UploadPolicy
pub fn build(&self) -> UploadPolicy
生成上传策略
Examples found in repository?
More examples
src/upload_token.rs (line 454)
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
fn make_policy(&self) -> AnyResult<UploadPolicy> {
let mut builder =
UploadPolicyBuilder::new_policy_for_bucket(self.bucket.to_string(), self.upload_token_lifetime);
if let Some(on_policy_generated) = self.on_policy_generated.as_ref() {
on_policy_generated(&mut builder)?;
}
Ok(builder.build())
}
}
impl<C: Clone> Debug for BucketUploadTokenProvider<C> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("BucketUploadTokenProvider")
.field("bucket", &self.bucket)
.field("upload_token_lifetime", &self.upload_token_lifetime)
.finish()
}
}
impl<C: CredentialProvider + Clone> UploadTokenProvider for BucketUploadTokenProvider<C> {
#[inline]
fn access_key(&self, _opts: GetAccessKeyOptions) -> ParseResult<GotAccessKey> {
Ok(self
.credential
.get(Default::default())?
.into_credential()
.split()
.0
.into())
}
fn policy(&self, _opts: GetPolicyOptions) -> ParseResult<GotUploadPolicy<'_>> {
Ok(self.make_policy()?.into())
}
fn to_token_string(&self, _opts: ToStringOptions) -> ToStringResult<Cow<'_, str>> {
Ok(Cow::Owned(
self.credential
.get(Default::default())?
.sign_with_data(self.make_policy()?.as_json().as_bytes()),
))
}
}
/// 存储空间上传凭证构建器
#[derive(Clone)]
pub struct BucketUploadTokenProviderBuilder<C: Clone> {
inner: BucketUploadTokenProvider<C>,
}
impl<C: Clone> BucketUploadTokenProviderBuilder<C> {
/// 设置上传凭证回调函数
#[inline]
#[must_use]
pub fn on_policy_generated(
mut self,
callback: impl Fn(&mut UploadPolicyBuilder) -> AnyResult<()> + Sync + Send + 'static,
) -> Self {
self.inner.on_policy_generated = Some(Arc::new(callback));
self
}
/// 构造存储空间上传凭证
#[inline]
pub fn build(self) -> BucketUploadTokenProvider<C> {
self.inner
}
}
impl<C: Clone> Debug for BucketUploadTokenProviderBuilder<C> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("BucketUploadTokenProviderBuilder")
.field("bucket", &self.inner.bucket)
.field("upload_token_lifetime", &self.inner.upload_token_lifetime)
.finish()
}
}
/// 基于对象的动态生成
///
/// 根据对象的快速生成上传凭证实例
#[derive(Clone)]
pub struct ObjectUploadTokenProvider<C: Clone> {
bucket: BucketName,
object: ObjectName,
upload_token_lifetime: Duration,
credential: C,
on_policy_generated: Option<OnPolicyGeneratedCallback>,
}
impl<C: Clone> ObjectUploadTokenProvider<C> {
/// 基于存储空间和对象名称和认证信息动态生成上传凭证实例
#[inline]
pub fn new(
bucket: impl Into<BucketName>,
object: impl Into<ObjectName>,
upload_token_lifetime: Duration,
credential: C,
) -> Self {
Self::builder(bucket, object, upload_token_lifetime, credential).build()
}
/// 创建对象上传凭证构建器
#[inline]
pub fn builder(
bucket: impl Into<BucketName>,
object: impl Into<ObjectName>,
upload_token_lifetime: Duration,
credential: C,
) -> ObjectUploadTokenProviderBuilder<C> {
ObjectUploadTokenProviderBuilder {
inner: Self {
bucket: bucket.into(),
object: object.into(),
upload_token_lifetime,
credential,
on_policy_generated: None,
},
}
}
fn make_policy(&self) -> AnyResult<UploadPolicy> {
let mut builder = UploadPolicyBuilder::new_policy_for_object(
self.bucket.to_string(),
self.object.to_string(),
self.upload_token_lifetime,
);
if let Some(on_policy_generated) = self.on_policy_generated.as_ref() {
on_policy_generated(&mut builder)?;
}
Ok(builder.build())
}
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.