### Install Qiniu Rust SDK Dependencies Source: https://context7.com/qiniu/rust-sdk/llms.txt This TOML snippet shows how to add the Qiniu SDK for Rust and its individual crates to your project's Cargo.toml file. It demonstrates both the full SDK entry point with feature flags and the installation of specific crates for granular control. ```toml [dependencies] # Full SDK entry point (recommended) qiniu-sdk = { version = "0.2.4", features = ["upload", "download", "objects", "upload-token"] } # Or individual crates qiniu-credential = "0.2.4" qiniu-etag = "0.2.4" qiniu-upload-token = "0.2.4" qiniu-upload-manager = "0.2.4" qiniu-download-manager = "0.2.4" qiniu-objects-manager = "0.2.4" ``` -------------------------------- ### Async Download Source: https://context7.com/qiniu/rust-sdk/llms.txt Demonstrates how to download a file asynchronously using the Qiniu Rust SDK. It shows the setup for the download manager and the process of downloading to a specified path. ```APIDOC ## Async Download ### Description This endpoint demonstrates how to download a file asynchronously from Qiniu storage. It covers initializing the `DownloadManager` and performing the download to a local file. ### Method Asynchronous function call (`async_download`, `async_to_path`) ### Endpoint Not directly applicable, as this is an SDK function call. ### Parameters - `bucket_name` (string) - The name of the bucket containing the file. - `object_name` (string) - The path and name of the object to download. - `credential` (struct) - Qiniu credentials (`AccessKey`, `SecretKey`). - `output_path` (string) - The local path where the downloaded file will be saved. ### Request Example ```rust use qiniu_sdk::download::{ apis::{credential::Credential, http_client::BucketDomainsQueryer}, DownloadManager, EndpointsUrlGenerator, UrlsSigner, }; async fn download_async() -> anyhow::Result<()> { let bucket_name = "your-bucket"; let object_name = "path/to/file.jpg"; let credential = Credential::new("your-access-key", "your-secret-key"); let download_manager = DownloadManager::new(UrlsSigner::new( credential.to_owned(), EndpointsUrlGenerator::builder( BucketDomainsQueryer::new().query(credential, bucket_name) ) .use_https(false) .build(), )); download_manager .async_download(object_name) .await? .async_to_path("/path/to/save/file.jpg") .await?; Ok(()) } ``` ### Response #### Success Response (200) Indicates successful download and save to the specified path. #### Response Example No direct HTTP response; success is indicated by the absence of errors in the SDK function calls. ``` -------------------------------- ### HTTP Client for Qiniu API Calls (Rust) Source: https://context7.com/qiniu/rust-sdk/llms.txt Provides a low-level HTTP client for interacting with Qiniu services, including automatic retries, region management, and authentication. This example demonstrates fetching a list of buckets from a private cloud. ```rust use qiniu_credential::Credential; use qiniu_http_client::{Authorization, HttpClient, Region, RegionsProviderEndpoints, ServiceName}; fn main() -> anyhow::Result<()> { // Private cloud: Get bucket list let region = Region::builder("z0") .add_uc_preferred_endpoint("uc-qos.your-private-cloud.com".parse()?) .build(); let credential = Credential::new("your-access-key", "your-secret-key"); let bucket_names: Vec = HttpClient::default() .get(&[ServiceName::Uc], RegionsProviderEndpoints::new(region)) .use_https(false) .authorization(Authorization::v2(credential)) .accept_json() .path("/buckets") .call()?, .parse_json()?, .into_body(); println!("Buckets: {:?}", bucket_names); Ok(()) } ``` -------------------------------- ### Batch Operations API Source: https://context7.com/qiniu/rust-sdk/llms.txt Allows for performing multiple object operations (like get info or delete) in a single request, improving efficiency. ```APIDOC ## Batch Operations ### Description This API enables the execution of multiple object management operations in a single API call, significantly reducing network latency and improving throughput. It supports batching operations such as retrieving object metadata or deleting multiple objects simultaneously. ### Methods - `batch_ops()`: Initializes a batch operation builder. - `add_operation()`: Adds a single operation (e.g., `stat_object`, `delete_object`) to the batch. - `call()`: Executes all added operations. ### Endpoint Not directly applicable, as this is an SDK function call. ### Parameters - `credential` (struct) - Qiniu credentials (`AccessKey`, `SecretKey`). - `bucket_name` (string) - The name of the bucket where operations will be performed. - Operations to be batched (e.g., `bucket.stat_object("file1.jpg")`, `bucket.delete_object("old1.jpg")`). ### Request Example ```rust use qiniu_sdk::objects::{apis::credential::Credential, ObjectsManager, OperationProvider}; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let object_manager = ObjectsManager::new(credential); let bucket = object_manager.bucket("your-bucket"); // Batch get object info let mut ops = bucket.batch_ops(); ops.add_operation(bucket.stat_object("file1.jpg")); ops.add_operation(bucket.stat_object("file2.jpg")); ops.add_operation(bucket.stat_object("file3.jpg")); let mut iter = ops.call(); while let Some(result) = iter.next() { match result { Ok(entry) => { println!("Hash: {:?}, Size: {:?}", entry.get_hash_as_str(), entry.get_size_as_u64()); } Err(err) => println!("Error: {:?}", err), } } // Batch delete let mut delete_ops = bucket.batch_ops(); delete_ops.add_operation(bucket.delete_object("old1.jpg")); delete_ops.add_operation(bucket.delete_object("old2.jpg")); delete_ops.add_operation(bucket.delete_object("old3.jpg")); let mut iter = delete_ops.call(); while let Some(result) = iter.next() { match result { Ok(_) => println!("Deleted successfully"), Err(err) => println!("Delete error: {:?}", err), } } Ok(()) } ``` ### Response #### Success Response (200) Returns an iterator where each item is a `Result` representing the outcome of an individual operation within the batch. It can be `Ok` with the operation's result or `Err` with an error object. #### Response Example For batch stat operations: ```json [ {"hash": "hash1", "size": 100}, {"hash": "hash2", "size": 200}, {"hash": "hash3", "size": 300} ] ``` For batch delete operations, success is indicated by `Ok(())` for each deleted item. ``` -------------------------------- ### Manage Qiniu Objects Source: https://context7.com/qiniu/rust-sdk/llms.txt Provides functionality for managing objects in Qiniu storage using the `ObjectsManager` crate. This includes operations like getting object metadata, modifying MIME types, renaming, copying, deleting objects, and setting lifecycle rules. ```rust use qiniu_sdk::objects::{apis::credential::Credential, ObjectsManager}; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let object_manager = ObjectsManager::new(credential); let bucket = object_manager.bucket("your-bucket"); // Get object metadata let response = bucket.stat_object("path/to/file.jpg").call()?; let entry = response.into_body(); println!("Hash: {}", entry.get_hash_as_str()); println!("Size: {} bytes", entry.get_size_as_u64()); println!("MIME Type: {}", entry.get_mime_type_as_str()); println!("Put Time: {}", entry.get_put_time_as_u64()); // Modify object MIME type bucket .modify_object_metadata("path/to/file.jpg", mime::APPLICATION_JSON) .call()?; // Move/rename object bucket .move_object_to("old-name.jpg", "your-bucket", "new-name.jpg") .call()?; // Copy object bucket .copy_object_to("source.jpg", "destination-bucket", "destination.jpg") .call()?; // Delete object bucket.delete_object("file-to-delete.jpg").call()?; // Set object lifecycle (delete after 10 days) use qiniu_sdk::objects::AfterDays; bucket .modify_object_life_cycle("temp-file.jpg") .delete_after_days(AfterDays::new(10)) .call()?; Ok(()) } ``` -------------------------------- ### Download Files from Public Qiniu Bucket (Rust) Source: https://context7.com/qiniu/rust-sdk/llms.txt Demonstrates downloading files from a public Qiniu storage bucket using the `DownloadManager`. This method uses a static domain and allows specifying whether to use HTTPS. Requires the bucket domain and object name. ```rust use qiniu_sdk::download::{DownloadManager, StaticDomainsUrlsGenerator}; fn main() -> anyhow::Result<()> { let object_name = "path/to/file.jpg"; let domain = "your-bucket-domain.com"; let local_path = "/path/to/save/file.jpg"; // Download from public bucket let download_manager = DownloadManager::new( StaticDomainsUrlsGenerator::builder(domain) .use_https(false) .build(), ); download_manager .download(object_name)? .to_path(local_path)?; println!("File downloaded to: {}", local_path); Ok(()) } ``` -------------------------------- ### Perform Asynchronous Download Source: https://context7.com/qiniu/rust-sdk/llms.txt Demonstrates how to asynchronously download a file from Qiniu storage. This function requires valid credentials and specifies the object key and the local path for saving the downloaded file. It utilizes the `DownloadManager` for handling the download process. ```rust use qiniu_sdk::download::{ apis::{credential::Credential, http_client::BucketDomainsQueryer}, DownloadManager, EndpointsUrlGenerator, UrlsSigner, }; async fn download_async() -> anyhow::Result<()> { let bucket_name = "your-bucket"; let object_name = "path/to/file.jpg"; let credential = Credential::new("your-access-key", "your-secret-key"); let download_manager = DownloadManager::new(UrlsSigner::new( credential.to_owned(), EndpointsUrlGenerator::builder( BucketDomainsQueryer::new().query(credential, bucket_name) ) .use_https(false) .build(), )); download_manager .async_download(object_name) .await? .async_to_path("/path/to/save/file.jpg") .await?; Ok(()) } ``` -------------------------------- ### List Objects in a Bucket Source: https://context7.com/qiniu/rust-sdk/llms.txt This Rust code snippet demonstrates how to list all objects within a specified Qiniu bucket. It iterates through the objects, retrieving and printing key details such as hash, size, and MIME type for each object. ```rust use qiniu_sdk::objects::{apis::credential::Credential, ObjectsManager}; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let object_manager = ObjectsManager::new(credential); let bucket = object_manager.bucket("your-bucket"); let mut iter = bucket.list().iter(); while let Some(entry) = iter.next() { let entry = entry?; println!( "{} hash: {} size: {} mime: ?", entry.get_key_as_str(), entry.get_hash_as_str(), entry.get_size_as_u64(), entry.get_mime_type_as_str(), ); } Ok(()) } ``` -------------------------------- ### Download Files from Private Qiniu Bucket (Rust) Source: https://context7.com/qiniu/rust-sdk/llms.txt Illustrates how to download files from a private Qiniu storage bucket using `DownloadManager` with URL signing. This requires Qiniu credentials in addition to the bucket domain and object name to generate a signed download URL. ```rust use qiniu_sdk::download::{ apis::credential::Credential, DownloadManager, StaticDomainsUrlsGenerator, UrlsSigner, }; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let object_name = "private/file.jpg"; let domain = "your-private-bucket-domain.com"; let local_path = "/path/to/save/private-file.jpg"; let download_manager = DownloadManager::new(UrlsSigner::new( credential, StaticDomainsUrlsGenerator::builder(domain) .use_https(false) .build(), )); download_manager .download(object_name)? .to_path(local_path)?; println!("Private file downloaded!"); Ok(()) } ``` -------------------------------- ### Upload Files with Qiniu Rust SDK (AutoUploader) Source: https://context7.com/qiniu/rust-sdk/llms.txt Demonstrates automatic file upload using the `AutoUploader` from the `qiniu-upload-manager` crate. It supports uploading from file paths or memory buffers, automatically choosing between single-part and multi-part uploads based on file size. Requires Qiniu credentials and bucket information. ```rust use qiniu_sdk::upload::{ apis::credential::Credential, AutoUploader, AutoUploaderObjectParams, UploadManager, UploadTokenSigner, }; use std::{io::Cursor, time::Duration}; fn main() -> anyhow::Result<()> { let access_key = "your-access-key"; let secret_key = "your-secret-key"; let bucket_name = "your-bucket"; let object_name = "uploaded-file.png"; let credential = Credential::new(access_key, secret_key); let upload_manager = UploadManager::builder(UploadTokenSigner::new_credential_provider( credential, bucket_name, Duration::from_secs(3600), )) .build(); let mut uploader: AutoUploader = upload_manager.auto_uploader(); // Upload from file path let params = AutoUploaderObjectParams::builder() .object_name(object_name) .file_name(object_name) .build(); uploader.upload_path("/path/to/local/file.png", params)?; println!("File uploaded successfully!"); // Upload from memory/reader let data = b"Hello, Qiniu Cloud!"; let params = AutoUploaderObjectParams::builder() .object_name("text-file.txt") .file_name("text-file.txt") .build(); uploader.upload_reader(Cursor::new(data), params)?; println!("Data uploaded successfully!"); Ok(()) } ``` -------------------------------- ### Perform Batch Operations on Qiniu Objects Source: https://context7.com/qiniu/rust-sdk/llms.txt Illustrates how to perform batch operations on Qiniu objects, significantly improving efficiency for multiple requests. This includes batch retrieval of object metadata and batch deletion of objects. Errors encountered during batch operations are handled individually. ```rust use qiniu_sdk::objects::{apis::credential::Credential, ObjectsManager, OperationProvider}; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let object_manager = ObjectsManager::new(credential); let bucket = object_manager.bucket("your-bucket"); // Batch get object info let mut ops = bucket.batch_ops(); ops.add_operation(bucket.stat_object("file1.jpg")); ops.add_operation(bucket.stat_object("file2.jpg")); ops.add_operation(bucket.stat_object("file3.jpg")); let mut iter = ops.call(); while let Some(result) = iter.next() { match result { Ok(entry) => { println!("Hash: {:?}, Size: ?", entry.get_hash_as_str(), entry.get_size_as_u64()); } Err(err) => println!("Error: ?", err), } } // Batch delete let mut delete_ops = bucket.batch_ops(); delete_ops.add_operation(bucket.delete_object("old1.jpg")); delete_ops.add_operation(bucket.delete_object("old2.jpg")); delete_ops.add_operation(bucket.delete_object("old3.jpg")); let mut iter = delete_ops.call(); while let Some(result) = iter.next() { match result { Ok(_) => println!("Deleted successfully"), Err(err) => println!("Delete error: ?", err), } } Ok(()) } ``` -------------------------------- ### List Objects in Bucket Source: https://context7.com/qiniu/rust-sdk/llms.txt Enables listing all objects within a specified bucket. It provides an iterator to go through each object and retrieve its details. ```APIDOC ## List Objects in Bucket ### Description This API allows you to retrieve a list of all objects contained within a specific Qiniu bucket. It provides an iterator that yields each object's details, including its key (name/path), hash, size, and MIME type. ### Method `list().iter()` ### Endpoint Not directly applicable, as this is an SDK function call. ### Parameters - `credential` (struct) - Qiniu credentials (`AccessKey`, `SecretKey`). - `bucket_name` (string) - The name of the bucket to list objects from. ### Request Example ```rust use qiniu_sdk::objects::{apis::credential::Credential, ObjectsManager}; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let object_manager = ObjectsManager::new(credential); let bucket = object_manager.bucket("your-bucket"); let mut iter = bucket.list().iter(); while let Some(entry) = iter.next() { let entry = entry?; println!( "{} hash: {} size: {} mime:જી {}", entry.get_key_as_str(), entry.get_hash_as_str(), entry.get_size_as_u64(), entry.get_mime_type_as_str(), ); } Ok(()) } ``` ### Response #### Success Response (200) Returns an iterator that yields `ObjectEntry` structs for each object in the bucket. #### Response Example ``` file1.jpg hash: abcdef123456... size: 102400 mime: image/jpeg path/to/another/file.txt hash: fedcba654321... size: 512 mime: text/plain ``` ``` -------------------------------- ### Manage Qiniu Credentials in Rust Source: https://context7.com/qiniu/rust-sdk/llms.txt This Rust code demonstrates how to manage Qiniu credentials using the `qiniu-credential` crate. It shows creating a `Credential` from access and secret keys, signing arbitrary data, and generating signed URLs for private resource access. ```rust use qiniu_sdk::upload_token::{UploadPolicy, credential::Credential, prelude::*}; use std::time::Duration; fn main() -> anyhow::Result<()> { // Create credentials from Access Key and Secret Key let access_key = "your-access-key"; let secret_key = "your-secret-key"; let credential = Credential::new(access_key, secret_key); // Sign data using Qiniu signature algorithm let signature = credential.get(Default::default())?.sign(b"hello"); println!("Signature: {}", signature); // Output: "your-access-key:b84KVc-LroDiz0ebUANfdzSRxa0=" // Sign with data (for upload tokens) let signed_data = credential.get(Default::default())?.sign_with_data(b"hello"); println!("Signed with data: {}", signed_data); // Generate signed download URL for private bucket let url = "http://your-domain.com/private-file.jpg".parse()?; let signed_url = credential .get(Default::default())? .sign_download_url(url, Duration::from_secs(3600)); println!("Signed download URL: {}", signed_url); Ok(()) } ``` -------------------------------- ### Query Public Cloud Object Info (Rust) Source: https://context7.com/qiniu/rust-sdk/llms.txt Fetches object metadata from Qiniu Cloud Storage using the HTTP client. This snippet shows how to query object information by providing bucket name, key, and authentication credentials. ```rust use qiniu_credential::Credential; use qiniu_http_client::{ Authorization, BucketRegionsQueryer, HttpClient, RegionsProviderEndpoints, ServiceName, }; use serde_json::Value; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let value: Value = HttpClient::default() .get( &[ServiceName::Rs], RegionsProviderEndpoints::new( BucketRegionsQueryer::new() .query(credential.access_key().to_owned(), "your-bucket"), ), ) .path("/stat/dGVzdC1idWNrZXQ6dGVzdC1rZXk=") // Base64 encoded "bucket:key" .authorization(Authorization::v2(credential)) .accept_json() .call()?, .parse_json()?, .into_body(); println!("Object info: {:?}", value); Ok(()) } ``` -------------------------------- ### Upload Files to Private Cloud with Qiniu Rust SDK Source: https://context7.com/qiniu/rust-sdk/llms.txt Shows how to configure `AutoUploader` for uploading files to a private Qiniu cloud instance. This involves specifying custom endpoint URLs and potentially disabling HTTPS if the private cloud uses HTTP. Requires Qiniu credentials and bucket information. ```rust use qiniu_sdk::upload::{ apis::{ credential::Credential, http_client::EndpointsBuilder, }, AutoUploader, AutoUploaderObjectParams, UploadManager, UploadTokenSigner, }; use std::time::Duration; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let upload_manager = UploadManager::builder(UploadTokenSigner::new_credential_provider( credential, "your-bucket", Duration::from_secs(3600), )) .uc_endpoints( EndpointsBuilder::default() .add_preferred_endpoint("ucpub-qos.your-private-cloud.com".into()) .build(), ) .use_https(false) // Private clouds typically use HTTP .build(); let mut uploader: AutoUploader = upload_manager.auto_uploader(); let params = AutoUploaderObjectParams::builder() .object_name("private-cloud-file.png") .file_name("private-cloud-file.png") .build(); uploader.upload_path("/path/to/file.png", params)?; Ok(()) } ``` -------------------------------- ### Object Management API Source: https://context7.com/qiniu/rust-sdk/llms.txt Provides a comprehensive set of operations for managing objects within a Qiniu bucket, including retrieving metadata, modifying properties, renaming, copying, deleting, and setting lifecycle rules. ```APIDOC ## Object Management ### Description This API group allows for detailed management of objects stored in Qiniu buckets. Operations include retrieving object metadata (like hash, size, MIME type, put time), modifying the MIME type, renaming (moving) objects, copying objects to different buckets or locations, deleting objects, and configuring object lifecycle rules such as automatic deletion after a specified period. ### Methods - `stat_object`: Retrieve object metadata. - `modify_object_metadata`: Change the MIME type of an object. - `move_object_to`: Rename or move an object within or to another bucket. - `copy_object_to`: Copy an object to a different location or bucket. - `delete_object`: Remove an object from a bucket. - `modify_object_life_cycle`: Set lifecycle rules for an object, e.g., delete after days. ### Endpoints These are SDK function calls, not direct HTTP endpoints. ### Parameters - `credential` (struct) - Qiniu credentials (`AccessKey`, `SecretKey`). - `bucket_name` (string) - The name of the bucket. - `object_key` (string) - The key (path and name) of the object. - `new_object_key` (string) - The new key for renaming/moving. - `destination_bucket` (string) - The target bucket for copy/move operations. - `destination_object_key` (string) - The target object key for copy/move operations. - `mime_type` (e.g., `mime::APPLICATION_JSON`) - The new MIME type to set. - `after_days` (struct `AfterDays`) - Number of days after which the object should be deleted. ### Request Examples ```rust use qiniu_sdk::objects::{apis::credential::Credential, ObjectsManager, AfterDays}; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let object_manager = ObjectsManager::new(credential); let bucket = object_manager.bucket("your-bucket"); // Get object metadata let response = bucket.stat_object("path/to/file.jpg").call()?; let entry = response.into_body(); println!("Hash: {}", entry.get_hash_as_str()); println!("Size: {} bytes", entry.get_size_as_u64()); println!("MIME Type: {}", entry.get_mime_type_as_str()); println!("Put Time: {}", entry.get_put_time_as_u64()); // Modify object MIME type bucket .modify_object_metadata("path/to/file.jpg", mime::APPLICATION_JSON) .call()?; // Move/rename object bucket .move_object_to("old-name.jpg", "your-bucket", "new-name.jpg") .call()?; // Copy object bucket .copy_object_to("source.jpg", "destination-bucket", "destination.jpg") .call()?; // Delete object bucket.delete_object("file-to-delete.jpg").call()?; // Set object lifecycle (delete after 10 days) bucket .modify_object_life_cycle("temp-file.jpg") .delete_after_days(AfterDays::new(10)) .call()?; Ok(()) } ``` ### Response #### Success Response (200) Indicates the object management operation was successful. Response details vary by operation (e.g., metadata for `stat_object`, success confirmation for others). #### Response Example For `stat_object`: ```json { "hash": "some_hash", "size": 1024, "mimeType": "image/jpeg", "putTime": 1678886400 } ``` For other operations, success is typically indicated by an empty body or a status code indicating success. ``` -------------------------------- ### Calculate ETags with qiniu-etag Crate (Rust) Source: https://context7.com/qiniu/rust-sdk/llms.txt Computes Qiniu-specific ETags for files using both V1 and V2 algorithms. Supports calculation from raw bytes or from a reader, and is useful for verifying file integrity and managing uploads. ```rust use qiniu_etag::{EtagV1, EtagV2, prelude::*}; use std::io::{copy, Cursor}; fn main() -> std::io::Result<()> { // ETag V1 calculation from bytes let mut etag_v1 = EtagV1::new(); etag_v1.update(b"Hello, Qiniu!"); let result = etag_v1.finalize_fixed(); println!("ETag V1: {}", String::from_utf8_lossy(result.as_slice())); // ETag V1 calculation from reader let mut etag_v1 = EtagV1::new(); copy(&mut Cursor::new(b"file content here"), &mut etag_v1)?; let result = etag_v1.finalize_fixed(); println!("ETag V1 from reader: {}", String::from_utf8_lossy(result.as_slice())); // ETag V2 calculation (for multi-part uploads) let mut etag_v2 = EtagV2::new(); etag_v2.update(b"part1"); etag_v2.update(b"part2"); let result = etag_v2.finalize_fixed(); println!("ETag V2: {}", String::from_utf8_lossy(result.as_slice())); Ok(()) } ``` -------------------------------- ### Async File Upload with Qiniu Rust SDK Source: https://context7.com/qiniu/rust-sdk/llms.txt Provides an asynchronous function for uploading files using `AutoUploader`. This is suitable for non-blocking I/O operations in async Rust applications. It requires Qiniu credentials and bucket information, similar to the synchronous upload. ```rust use qiniu_sdk::upload::{ apis::credential::Credential, AutoUploader, AutoUploaderObjectParams, UploadManager, UploadTokenSigner, }; use std::time::Duration; async fn upload_async() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let upload_manager = UploadManager::builder(UploadTokenSigner::new_credential_provider( credential, "your-bucket", Duration::from_secs(3600), )) .build(); let mut uploader: AutoUploader = upload_manager.auto_uploader(); let params = AutoUploaderObjectParams::builder() .object_name("async-upload.png") .file_name("async-upload.png") .build(); uploader.async_upload_path("/path/to/file.png", params).await?; println!("Async upload completed!"); Ok(()) } ``` -------------------------------- ### Generate Qiniu Upload Tokens in Rust Source: https://context7.com/qiniu/rust-sdk/llms.txt This Rust code snippet illustrates generating various types of upload tokens using the `qiniu-upload-token` crate. It covers simple bucket uploads, overwrite uploads, custom return bodies, and tokens with callback configurations for client-side uploads. ```rust use qiniu_sdk::upload_token::{UploadPolicy, credential::Credential, prelude::*}; use std::time::Duration; fn main() -> anyhow::Result<()> { let credential = Credential::new("your-access-key", "your-secret-key"); let bucket_name = "your-bucket"; // Simple bucket upload token (valid for 1 hour) let upload_token = UploadPolicy::new_for_bucket(bucket_name, Duration::from_secs(3600)) .build_token(credential.clone(), Default::default())?; println!("Upload Token: {}", upload_token); // Overwrite upload token for specific object let object_name = "path/to/file.jpg"; let overwrite_token = UploadPolicy::new_for_object(bucket_name, object_name, Duration::from_secs(3600)) .build_token(credential.clone(), Default::default())?; println!("Overwrite Token: {}", overwrite_token); // Custom return body upload token let custom_token = UploadPolicy::new_for_object(bucket_name, object_name, Duration::from_secs(3600)) .return_body("{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"fsize\":$(fsize)}") .build_token(credential.clone(), Default::default())?; println!("Custom Return Token: {}", custom_token); // Upload token with callback to your server let callback_token = UploadPolicy::new_for_object(bucket_name, object_name, Duration::from_secs(3600)) .callback( &["http://api.example.com/qiniu/upload/callback"], "", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"fsize\":$(fsize)}", "application/json" ) .build_token(credential, Default::default())?; println!("Callback Token: {}", callback_token); Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.