Skip to main content

PrivateStorage

Struct PrivateStorage 

Source
pub struct PrivateStorage<'a, R: Runtime> { /* private fields */ }
Expand description

API of file storage intended for the app’s use only.

§Examples

use tauri_plugin_android_fs::{AndroidFsExt, PrivateDir};
 
async fn example(app: &tauri::AppHandle) {
    let api = app.android_fs_async();
    let ps = api.private_storage();
 
    // Resolve the absolute paths.
    // Files and directories in these locations can be fully managed using `std::fs`.
    let cache_dir_path: std::path::PathBuf = ps.resolve_path(PrivateDir::Cache).await?;
    let data_dir_path: std::path::PathBuf = ps.resolve_path(PrivateDir::Data).await?;
    let nobackup_data_dir_path: std::path::PathBuf = ps.resolve_path(PrivateDir::NoBackupData).await?;

    // These directories may also contain files created by other Tauri plugins
    // or the WebView runtime. To avoid conflicts, it is recommended to use
    // a uniquely named subdirectory for your application.
    let cache_dir_path = cache_dir_path.join("01K6049FVCD4SAGMAB6X20SA5S");
    let data_dir_path = data_dir_path.join("01K6049FVCD4SAGMAB6X20SA5S");
    let nobackup_data_dir_path = nobackup_data_dir_path.join("01K6049FVCD4SAGMAB6X20SA5S");
}

Implementations§

Source§

impl<'a, R: Runtime> SyncPrivateStorage<'a, R>

Source

pub fn resolve_path(&self, dir: PrivateDir) -> Result<PathBuf>

Returns the absolute path of an app-specific directory on the internal storage.

Files and directories in this location can be managed directly using std::fs.

This function does not guarantee directory creation.

Since these locations may also contain files created by other Tauri plugins or by the WebView runtime, it is recommended to create a uniquely named subdirectory for your application.

§Notes

Files in these locations are removed when the app is uninstalled.

When using PrivateDir::Cache, the system may automatically delete files when additional storage space is needed. Applications should not rely on this behavior and should clear cache files explicitly.

These directories are inaccessible to other apps under normal circumstances. On rooted devices or when the user has elevated privileges, their contents may still be accessible.

The returned path may change if the app is moved to adopted storage. Persist only relative paths if the path needs to be stored.

Each Android user has a separate app-specific directory.

§Support

All Android versions supported by Tauri.

Source

pub fn resolve_uri( &self, dir: PrivateDir, relative_path: impl AsRef<Path>, ) -> Result<FsUri>

See PrivateStorage::resolve_path and [FileUri::from_path]

Auto Trait Implementations§

§

impl<'a, R> Freeze for SyncPrivateStorage<'a, R>

§

impl<'a, R> RefUnwindSafe for SyncPrivateStorage<'a, R>

§

impl<'a, R> Send for SyncPrivateStorage<'a, R>

§

impl<'a, R> Sync for SyncPrivateStorage<'a, R>

§

impl<'a, R> Unpin for SyncPrivateStorage<'a, R>

§

impl<'a, R> UnsafeUnpin for SyncPrivateStorage<'a, R>

§

impl<'a, R> UnwindSafe for SyncPrivateStorage<'a, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.