Rust API Client

Rust integration handles uploads and file operations by wrapping Uploadcare Upload API and REST API. This comprehensive API client lets you use most of the Uploadcare features from within your Rust app.

GitHub →

Features

Uploading (Upload API):

  • Upload files from local storage and URLs (up to 5 TB)
  • Multipart uploading for large files
  • Uploading network to speed uploading jobs (like CDN)

File management (REST API):

  • Get file info and perform various operations (store/delete/copy) with them
  • Work with groups of files
  • Get info about account project
  • Manage webhooks
  • Convert documents
  • Encode and transform videos

Image processing (URL API):

  • Compression
  • Geometry
  • Colors
  • Definition
  • Image and text overlays
  • Rotations
  • Recognition
  • File info
  • Proxy (fetch)

Security features:

  • Secure authentication
  • Secure uploads (signed uploads)
  • Secure delivery (signed URLs)

Requirements

  • rustc 1.43
  • cargo 1.43

Installation

Ensure you have Cargo, the Rust dependency manager, installed on your system. If not, follow the installation instructions.

Open your cargo.toml file and add the following code:

1[dependencies]
2uploadcare = "^0.1"

Configuration

By default the full is enabled (REST and Upload API).

To reduce the code size, disable default features and enable just the APIs you use:

1# Example: REST API only
2uploadcare = { version = "*", default-features = false, features = ["rest"] }

Creating a client:

1use ucare;
2use ucare::file;
3use ucare::upload;
4
5let creds = ucare::apicreds {
6 pub_key: "YOUR_PUBLIC_KEY",
7 secret_key: "YOUR_SECRET_KEY",
8};
9
10// creating rest client
11let config = ucare::RestConfig {
12 sign_based_auth: true,
13 api_version: ucare::RestApiVersion::v06,
14};
15let rest_client = ucare::RestClient::new(config, creds).unwrap();
16
17// creating upload client
18let config = ucare::UploadConfig {
19 sign_based_upload: true,
20};
21let upload_client = ucare::UploadClient::new(config, creds).unwrap();

Usage example

For a comprehensive list of examples, check out the API documentation. Below are a few usage examples:

1let file_svc = file::new_svc(&rest_client);
2
3let file_id = "b7c1bf20-0f4c-4ba4-b3a8-a74ebc663752";
4let file_info = file_svc.info(file_id).unwrap();
5println!("{}: {:?}", file_id, file_info);
6
7let upload_svc = upload::new_svc(&upload_client);
8
9let params = upload::FileParams {
10 path: "/path/to/file".to_string(),
11 name: "filename".to_string(),
12 to_store: Some(upload::ToStore::Auto),
13};
14let file = upload_svc.file(params).unwrap();
15println!("uploaded: {:?}", file.id);

Full documentation

Read the full documentation on GitHub.