pub struct Client { /* private fields */ }
Expand description
HTTP client used to interact with the pCloud API.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn get_file_checksum(
&self,
identifier: impl Into<FileIdentifier<'_>>,
) -> Result<FileChecksum>
pub async fn get_file_checksum( &self, identifier: impl Into<FileIdentifier<'_>>, ) -> Result<FileChecksum>
Retrieves the checksums and metadata for a file on pCloud.
This function calls the checksumfile
endpoint and returns a
FileChecksum
struct containing the MD5, SHA-1, and SHA-256 hashes,
as well as basic metadata for the specified file.
§Arguments
identifier
- A type that can be converted into aFileIdentifier
used to identify the file (e.g., by file ID or path).
§Errors
Returns a crate::Error
if the request fails or if the file cannot be found.
§Examples
let checksum = client.get_file_checksum("myfolder/myfile.txt").await?;
println!("SHA-1: {}", checksum.sha1);
Source§impl Client
impl Client
Sourcepub async fn delete_file(
&self,
identifier: impl Into<FileIdentifier<'_>>,
) -> Result<File>
pub async fn delete_file( &self, identifier: impl Into<FileIdentifier<'_>>, ) -> Result<File>
Deletes a file from pCloud.
This function calls the deletefile
endpoint to remove the specified file from the user’s pCloud storage.
It returns the metadata of the deleted file upon success.
§Arguments
identifier
- A type convertible into aFileIdentifier
that identifies the file to delete (e.g., by file ID or path).
§Returns
A File
struct containing metadata about the deleted file.
§Errors
Returns a crate::Error
if the file does not exist or the API request fails.
§Examples
let deleted_file = client.delete_file("myfolder/myfile.txt").await?;
println!("Deleted file ID: {}", deleted_file.file_id);
Source§impl Client
impl Client
Sourcepub async fn move_file(
&self,
file: impl Into<FileIdentifier<'_>>,
to_folder: impl Into<FolderIdentifier<'_>>,
) -> Result<File>
pub async fn move_file( &self, file: impl Into<FileIdentifier<'_>>, to_folder: impl Into<FolderIdentifier<'_>>, ) -> Result<File>
Moves a file to a different folder on pCloud.
This function calls the renamefile
API endpoint to move the specified file
to a new folder. The file is identified either by its file ID or by path.
§Arguments
file
- A value that can be converted into aFileIdentifier
(e.g., file ID or path).to_folder
- A value that can be converted into aFolderIdentifier
representing the destination folder.
§Returns
On success, returns a File
struct containing metadata about the moved file.
§Errors
Returns a crate::Error
if the file or folder is not found, or if the API request fails.
§Examples
let file = client.move_file(12345678u64, "/new/folder").await?;
println!("Moved file name: {}", file.base.name);
Source§impl Client
impl Client
Sourcepub async fn rename_file<'a>(
&self,
identifier: impl Into<FileIdentifier<'a>>,
name: impl Into<Cow<'a, str>>,
) -> Result<File>
pub async fn rename_file<'a>( &self, identifier: impl Into<FileIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<File>
Renames a file on pCloud.
This function calls the renamefile
API endpoint to change the name of a file.
The file can be specified by its ID or path, and the new name must be a string.
§Arguments
identifier
- A value convertible into aFileIdentifier
representing the file to rename.name
- The new name to assign to the file.
§Returns
On success, returns a File
struct containing metadata about the renamed file.
§Errors
Returns a crate::Error
if the file doesn’t exist or if the API request fails.
§Examples
let renamed = client.rename_file(12345678u64, "new_name.txt").await?;
println!("Renamed file: {:?}", renamed.base.name);
Source§impl Client
impl Client
Sourcepub async fn upload_files(
&self,
parent: impl Into<FolderIdentifier<'_>>,
files: MultiFileUpload,
) -> Result<Vec<File>>
pub async fn upload_files( &self, parent: impl Into<FolderIdentifier<'_>>, files: MultiFileUpload, ) -> Result<Vec<File>>
Uploads multiple files to a specified folder on pCloud.
This method uses multipart form submission to upload several files in a single request.
§Arguments
parent
- A value convertible into aFolderIdentifier
representing the destination folder.files
- AMultiFileUpload
builder containing the files to upload.
§Returns
On success, returns a list of File
metadata for each uploaded file.
§Errors
Returns a crate::Error
if the upload fails due to network issues,
invalid input, or server-side errors.
§Examples
use bytes::Bytes;
use futures_util::stream;
let data = vec![Ok(Bytes::from_static(b"hello world"))];
let stream = stream::iter(data);
let upload = pcloud::file::upload::MultiFileUpload::default()
.with_stream_entry("hello.txt", 11, stream);
let uploaded = client.upload_files("/my-folder", upload).await?;
println!("Uploaded {} file(s)", uploaded.len());
Source§impl Client
impl Client
Sourcepub async fn create_folder<'a>(
&self,
parent: impl Into<FolderIdentifier<'a>>,
name: impl Into<Cow<'a, str>>,
) -> Result<Folder>
pub async fn create_folder<'a>( &self, parent: impl Into<FolderIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<Folder>
Creates a new folder inside the specified parent folder on pCloud.
This function calls the createfolder
API endpoint and will return
an error if a folder with the same name already exists in the target location.
§Arguments
parent
- A value convertible into aFolderIdentifier
representing the parent folder.name
- The name of the folder to create.
§Returns
On success, returns a Folder
representing the newly created folder.
§Errors
Returns a crate::Error
if the folder already exists or the request fails.
§Examples
let folder = client.create_folder(0, "new-folder").await?;
println!("Created folder: {}", folder.base.name);
Source§impl Client
impl Client
Sourcepub async fn create_folder_if_not_exists<'a>(
&self,
parent: impl Into<FolderIdentifier<'a>>,
name: impl Into<Cow<'a, str>>,
) -> Result<Folder>
pub async fn create_folder_if_not_exists<'a>( &self, parent: impl Into<FolderIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<Folder>
Creates a new folder if it does not already exist in the specified location.
This function calls the createfolderifnotexists
API endpoint, which ensures
the operation is idempotent: if a folder with the given name exists, it will be returned.
Otherwise, a new folder is created.
§Arguments
parent
- A value convertible into aFolderIdentifier
representing the parent folder.name
- The name of the folder to create or return if it exists.
§Returns
A Folder
representing the existing or newly created folder.
§Errors
Returns a crate::Error
if the request fails for any reason other than the folder already existing.
§Examples
let folder = client.create_folder_if_not_exists(0, "my-folder").await?;
println!("Folder ID: {}", folder.folder_id);
Source§impl Client
impl Client
Sourcepub async fn delete_folder<'a>(
&self,
identifier: impl Into<FolderIdentifier<'a>>,
) -> Result<Folder>
pub async fn delete_folder<'a>( &self, identifier: impl Into<FolderIdentifier<'a>>, ) -> Result<Folder>
Deletes an empty folder from pCloud.
This function calls the deletefolder
API endpoint. It will fail
if the folder is not empty or cannot be deleted.
§Arguments
identifier
- A value that can be converted into aFolderIdentifier
(e.g., folder ID or path).
§Returns
On success, returns the metadata of the deleted folder as a Folder
object.
§Errors
Returns a crate::Error
if the folder does not exist, is not empty, or the API call fails.
§Examples
let folder = client.delete_folder("/my/empty/folder").await?;
println!("Deleted folder: {}", folder.base.name);
Source§impl Client
impl Client
Sourcepub async fn delete_folder_recursive<'a>(
&self,
identifier: impl Into<FolderIdentifier<'a>>,
) -> Result<RecursivePayload>
pub async fn delete_folder_recursive<'a>( &self, identifier: impl Into<FolderIdentifier<'a>>, ) -> Result<RecursivePayload>
Recursively deletes a folder and all of its contents from pCloud.
This function calls the deletefolderrecursive
API endpoint and removes
the folder and everything inside it (including subfolders and files).
§Arguments
identifier
- A value that can be converted into aFolderIdentifier
(e.g., folder ID or path).
§Returns
A RecursivePayload
struct containing statistics about how many files and folders were deleted.
§Errors
Returns a crate::Error
if the folder does not exist or the API call fails.
§Examples
let result = client.delete_folder_recursive(12345u64).await?;
println!(
"Deleted {} files and {} folders",
result.deleted_files,
result.deleted_folders
);
Source§impl Client
impl Client
Sourcepub async fn list_folder(
&self,
identifier: impl Into<FolderIdentifier<'_>>,
) -> Result<Folder>
pub async fn list_folder( &self, identifier: impl Into<FolderIdentifier<'_>>, ) -> Result<Folder>
Lists the contents of a folder on pCloud.
This is a convenience method that calls crate::Client::list_folder_with_options
with default options.
It will list the folder’s immediate contents, including files and subfolders.
§Arguments
identifier
- A value convertible into aFolderIdentifier
(e.g., path or folder ID).
§Returns
A Folder
struct containing metadata and child entries.
§Errors
Returns a crate::Error
if the folder cannot be listed.
§Examples
let folder = client.list_folder("/Documents").await?;
println!("Folder has {:?} entries", folder.contents.map(|res| res.len()).unwrap_or(0));
Sourcepub async fn list_folder_with_options(
&self,
identifier: impl Into<FolderIdentifier<'_>>,
options: ListFolderOptions,
) -> Result<Folder>
pub async fn list_folder_with_options( &self, identifier: impl Into<FolderIdentifier<'_>>, options: ListFolderOptions, ) -> Result<Folder>
Lists the contents of a folder with custom options.
This method gives fine-grained control over how the folder contents are returned
by the listfolder
endpoint, such as recursive listing and filtering.
§Arguments
identifier
- A value convertible into aFolderIdentifier
(e.g., path or folder ID).options
- AListFolderOptions
struct specifying what to include in the listing.
§Returns
A Folder
with metadata and contents matching the provided options.
§Errors
Returns a crate::Error
if the folder is inaccessible or the API call fails.
§Examples
use pcloud::folder::list::ListFolderOptions;
let options = ListFolderOptions::default()
.with_recursive()
.with_show_deleted();
let folder = client.list_folder_with_options("/Backup", options).await?;
println!("Listed folder: {:?}", folder.base.name);
Source§impl Client
impl Client
Sourcepub async fn move_folder(
&self,
folder: impl Into<FolderIdentifier<'_>>,
to_folder: impl Into<FolderIdentifier<'_>>,
) -> Result<Folder>
pub async fn move_folder( &self, folder: impl Into<FolderIdentifier<'_>>, to_folder: impl Into<FolderIdentifier<'_>>, ) -> Result<Folder>
Moves a folder to a new location in pCloud.
This function calls the renamefolder
API endpoint and moves the specified folder
from its current location to the target folder. Both the source and destination can
be specified either by folder ID or path.
§Arguments
folder
- A value that can be converted into aFolderIdentifier
(e.g., folder ID or path).to_folder
- The target folder identifier (e.g., folder ID or path) to move the folder into.
§Returns
A Folder
struct containing the metadata of the moved folder.
§Errors
Returns a crate::Error
if the move operation fails, such as if either folder is not accessible
or the API call encounters an issue.
§Examples
let moved_folder = client.move_folder("/OldFolder", "/NewFolder").await?;
println!("Moved folder: {:?}", moved_folder.base.name);
Source§impl Client
impl Client
Sourcepub async fn rename_folder<'a>(
&self,
identifier: impl Into<FolderIdentifier<'a>>,
name: impl Into<Cow<'a, str>>,
) -> Result<Folder>
pub async fn rename_folder<'a>( &self, identifier: impl Into<FolderIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<Folder>
Renames an existing folder in pCloud.
This function calls the renamefolder
API endpoint to rename the specified folder.
The folder is identified either by its folder ID or its path, and the new name is provided
as a string.
§Arguments
identifier
- The identifier for the folder to be renamed, which can be provided either by folder ID or path.name
- The new name for the folder.
§Returns
A Folder
struct containing the metadata of the renamed folder.
§Errors
Returns a crate::Error
if the rename operation fails, for example, if the folder does
not exist or the API request encounters an issue.
§Examples
let renamed_folder = client.rename_folder("/OldFolder", "NewFolderName").await?;
println!("Renamed folder: {:?}", renamed_folder.base.name);
Source§impl Client
impl Client
Sourcepub async fn get_digest(&self) -> Result<Digest>
pub async fn get_digest(&self) -> Result<Digest>
Generates an authentication digest, valid for 30 seconds.
§Returns
A Digest
struct containing the digest itself
§Errors
Returns a crate::Error
if the folder cannot be listed.
§Examples
let value = client.get_digest().await?;
println!("{:?}", value);
Source§impl Client
impl Client
Sourcepub async fn get_token(&self) -> Result<String>
pub async fn get_token(&self) -> Result<String>
Generate a new token based on the provided credentials
§Returns
A [Digest
] struct containing the digest itself
§Errors
Returns a crate::Error
if the folder cannot be listed.
§Examples
let value = client.get_digest().await?;
println!("{:?}", value);
Source§impl Client
impl Client
Sourcepub async fn get_audio_link(
&self,
identifier: impl Into<FileIdentifier<'_>>,
) -> Result<StreamingLinkList>
pub async fn get_audio_link( &self, identifier: impl Into<FileIdentifier<'_>>, ) -> Result<StreamingLinkList>
Sourcepub async fn get_audio_link_with_params(
&self,
identifier: impl Into<FileIdentifier<'_>>,
params: GetAudioLinkParams,
) -> Result<StreamingLinkList>
pub async fn get_audio_link_with_params( &self, identifier: impl Into<FileIdentifier<'_>>, params: GetAudioLinkParams, ) -> Result<StreamingLinkList>
Gets an audio link using both the file identifier and additional parameters.
§Arguments
identifier
- The identifier of the file.params
- The parameters to customize the audio link (e.g., audio bit rate, force download).
§Returns
A result containing the StreamingLinkList
with the generated audio links.
Source§impl Client
impl Client
Sourcepub async fn get_file_link(
&self,
identifier: impl Into<FileIdentifier<'_>>,
) -> Result<StreamingLinkList>
pub async fn get_file_link( &self, identifier: impl Into<FileIdentifier<'_>>, ) -> Result<StreamingLinkList>
Sourcepub async fn get_file_link_with_params(
&self,
identifier: impl Into<FileIdentifier<'_>>,
params: GetFileLinkParams<'_>,
) -> Result<StreamingLinkList>
pub async fn get_file_link_with_params( &self, identifier: impl Into<FileIdentifier<'_>>, params: GetFileLinkParams<'_>, ) -> Result<StreamingLinkList>
Gets a file link using both the file identifier and additional parameters.
§Arguments
identifier
- The identifier of the file.params
- The parameters to customize the file link (e.g., force download, content type, etc.).
§Returns
A result containing the StreamingLinkList
with the generated file links.
Source§impl Client
impl Client
Sourcepub async fn get_video_link(
&self,
identifier: impl Into<FileIdentifier<'_>>,
) -> Result<StreamingLinkList>
pub async fn get_video_link( &self, identifier: impl Into<FileIdentifier<'_>>, ) -> Result<StreamingLinkList>
Sourcepub async fn get_video_link_with_params(
&self,
identifier: impl Into<FileIdentifier<'_>>,
params: GetVideoLinkParams<'_>,
) -> Result<StreamingLinkList>
pub async fn get_video_link_with_params( &self, identifier: impl Into<FileIdentifier<'_>>, params: GetVideoLinkParams<'_>, ) -> Result<StreamingLinkList>
Gets a video link using both the file identifier and additional parameters.
§Arguments
identifier
- The identifier of the file.params
- The parameters to customize the video link (e.g., audio bit rate, video bit rate, resolution).
§Returns
A result containing the StreamingLinkList
with the generated video links.
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Creates a new ClientBuilder
instance for custom configuration.
Sourcepub fn new(
base_url: impl Into<Cow<'static, str>>,
credentials: Credentials,
) -> Result<Self>
pub fn new( base_url: impl Into<Cow<'static, str>>, credentials: Credentials, ) -> Result<Self>
Creates a new Client
with the specified base URL and credentials.
§Errors
Returns a reqwest::Error
if the inner HTTP client fails to build.
Sourcepub fn set_credentials(&mut self, credentials: Credentials)
pub fn set_credentials(&mut self, credentials: Credentials)
Update the credentials of the client
Sourcepub fn with_credentials(self, credentials: Credentials) -> Self
pub fn with_credentials(self, credentials: Credentials) -> Self
Take ownership of the client and update the credentials