React Native Cloud Storage

CloudStorage

Constructors

Constructor

new CloudStorage(
  provider?: CloudStorageProvider,
  options?: CloudStorageProviderOptionsValue,
): RNCloudStorage;

Creates a new RNCloudStorage instance for the given provider.

Parameters

ParameterTypeDescription
provider?CloudStorageProviderThe provider to create the instance for. Defaults to the default provider for the current platform.
options?CloudStorageProviderOptionsValue-

Returns

RNCloudStorage

Methods

appendFile()

appendFile(
  path: string,
  data: string,
  scope?: CloudStorageScope,
): Promise<void>;

Appends the data to the file at the given path, creating the file if it doesn't exist.

Parameters

ParameterTypeDescription
pathstringThe file to append to.
datastringThe data to append.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the current provider.

Returns

Promise<void>

A promise that resolves when the data has been appended.


downloadFile()

Call Signature

downloadFile(
  path: string,
  scope?: CloudStorageScope,
): Promise<void>;

Triggers synchronization for the file at the given path. Does not have any effect on Google Drive.

Parameters
ParameterTypeDescription
pathstringThe file to trigger synchronization for.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.
Returns

Promise<void>

A promise that resolves once the synchronization has been triggered.

Deprecated

Use triggerSync instead.

Call Signature

downloadFile(
  remotePath: string,
  localPath: string,
  scope?: CloudStorageScope,
): Promise<void>;

Downloads the cloud file at the given remote path to the given local path.

Parameters
ParameterTypeDescription
remotePathstringThe remote path of the file to download from the cloud.
localPathstringThe local path to download the cloud file to.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.
Returns

Promise<void>


exists()

exists(
  path: string,
  scope?: CloudStorageScope,
): Promise<boolean>;

Tests whether or not the file at the given path exists.

Parameters

ParameterTypeDescription
pathstringThe path to test.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<boolean>

A promise that resolves to true if the path exists, false otherwise.


getProvider()

getProvider(): CloudStorageProvider;

Gets the current CloudStorageProvider.

Returns

CloudStorageProvider

The current CloudStorageProvider.


getProviderOptions()

getProviderOptions(): CloudStorageProviderOptionsValue;

Gets the current options for the current provider.

Returns

CloudStorageProviderOptionsValue

The current options for the current provider.


isCloudAvailable()

isCloudAvailable(): Promise<boolean>;

Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be unavailable right after app launch or if the user is not logged in.

Returns

Promise<boolean>

A promise that resolves to true if the cloud storage is available, false otherwise.


mkdir()

mkdir(path: string, scope?: CloudStorageScope): Promise<void>;

Creates a new directory at the given path.

Parameters

ParameterTypeDescription
pathstringThe directory to create.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<void>

A promise that resolves when the directory has been created.


readdir()

readdir(
  path: string,
  scope?: CloudStorageScope,
): Promise<string[]>;

Lists the contents of the directory at the given path.

Parameters

ParameterTypeDescription
pathstringThe directory to list.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<string[]>

A promise that resolves to an array of file names, excluding '.' and '..'.


readFile()

readFile(
  path: string,
  scope?: CloudStorageScope,
): Promise<string>;

Reads the contents of the file at the given path.

Parameters

ParameterTypeDescription
pathstringThe file to read.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<string>

A promise that resolves to the contents of the file.


rmdir()

rmdir(
  path: string,
  options?: object,
  scope?: CloudStorageScope,
): Promise<void>;

Deletes the directory at the given path.

Parameters

ParameterTypeDescription
pathstringThe directory to delete.
options?{ recursive?: boolean; }Options for the delete operation. Defaults to { recursive: false }.
options.recursive?boolean-
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<void>

A promise that resolves when the directory has been deleted.


setProvider()

setProvider(provider: CloudStorageProvider): void;

Sets the current CloudStorageProvider.

Parameters

ParameterTypeDescription
providerCloudStorageProviderThe provider to set.

Returns

void


setProviderOptions()

setProviderOptions(
  options: CloudStorageProviderOptionsValue,
): void;

Sets the options for the current provider.

Parameters

ParameterTypeDescription
optionsCloudStorageProviderOptionsValueThe options to set for the provider.

Returns

void


stat()

stat(
  path: string,
  scope?: CloudStorageScope,
): Promise<CloudStorageFileStat>;

Gets the size, creation time, and modification time of the file at the given path.

Parameters

ParameterTypeDescription
pathstringThe file to stat.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<CloudStorageFileStat>

A promise that resolves to the CloudStorageFileStat object.


subscribeToCloudAvailability()

subscribeToCloudAvailability(
  listener: (available: boolean) => void,
): void;

Parameters

ParameterType
listener(available: boolean) => void

Returns

void


triggerSync()

iCloud
triggerSync(
  path: string,
  scope?: CloudStorageScope,
): Promise<void>;

Triggers synchronization for the file at the given path. Does not have any effect on Google Drive.

Parameters

ParameterTypeDescription
pathstringThe file to trigger synchronization for.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<void>

A promise that resolves once the synchronization has been triggered.


unlink(path: string, scope?: CloudStorageScope): Promise<void>;

Deletes the file at the given path.

Parameters

ParameterTypeDescription
pathstringThe file to delete.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<void>

A promise that resolves when the file has been deleted.


unsubscribeFromCloudAvailability()

unsubscribeFromCloudAvailability(
  listener: (available: boolean) => void,
): void;

Parameters

ParameterType
listener(available: boolean) => void

Returns

void


uploadFile()

uploadFile(
  remotePath: string,
  localPath: string,
  options: object,
  scope?: CloudStorageScope,
): Promise<void>;

Uploads the file at the given local path to the given path, creating it if it doesn't exist or overwriting it if it does.

Parameters

ParameterTypeDescription
remotePathstringThe remote path to upload to.
localPathstringThe local path of the file to upload.
options{ mimeType: string; }The options for the upload. Must contain a mimeType property.
options.mimeTypestring-
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<void>

A promise that resolves when the file has been uploaded.


writeFile()

writeFile(
  path: string,
  data: string,
  scope?: CloudStorageScope,
): Promise<void>;

Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does.

Parameters

ParameterTypeDescription
pathstringThe file to write to.
datastringThe data to write.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<void>

A promise that resolves when the file has been written.


appendFile()

static appendFile(
  path: string,
  data: string,
  scope?: CloudStorageScope,
): Promise<void>;

Appends the data to the file at the given path in the provider of the default static instance, creating the file if it doesn't exist.

Parameters

ParameterTypeDescription
pathstringThe file to append to.
datastringThe data to append.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<void>

A promise that resolves when the data has been appended.


downloadFile()

Call Signature

static downloadFile(
  path: string,
  scope?: CloudStorageScope,
): Promise<void>;

Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive.

Parameters
ParameterTypeDescription
pathstringThe file to trigger synchronization for.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.
Returns

Promise<void>

A promise that resolves once the synchronization has been triggered.

Deprecated

Use triggerSync instead.

Call Signature

static downloadFile(
  remotePath: string,
  localPath: string,
  scope?: CloudStorageScope,
): Promise<void>;

Downloads the cloud file at the given remote path to the given local path.

Parameters
ParameterTypeDescription
remotePathstringThe remote path of the file to download from the cloud.
localPathstringThe local path to download the cloud file to.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.
Returns

Promise<void>


exists()

static exists(
  path: string,
  scope?: CloudStorageScope,
): Promise<boolean>;

Tests whether or not the file at the given path exists in the provider of the default static instance.

Parameters

ParameterTypeDescription
pathstringThe path to test.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<boolean>

A promise that resolves to true if the path exists, false otherwise.


getDefaultInstance()

static getDefaultInstance(): RNCloudStorage;

Returns

RNCloudStorage


getDefaultProvider()

static getDefaultProvider(): CloudStorageProvider;

Gets the default CloudStorageProvider for the current platform.

Returns

CloudStorageProvider

The default CloudStorageProvider.


getProvider()

static getProvider(): CloudStorageProvider;

Gets the current provider of the default static instance.

Returns

CloudStorageProvider

The current provider of the default static instance.


getProviderOptions()

static getProviderOptions(): CloudStorageProviderOptionsValue;

Gets the current options for the provider of the default static instance.

Returns

CloudStorageProviderOptionsValue

The current options for the provider of the default static instance.


getSupportedProviders()

static getSupportedProviders(): CloudStorageProvider[];

Gets the list of supported CloudStorageProviders on the current platform.

Returns

CloudStorageProvider[]

An array of supported CloudStorageProviders.


isCloudAvailable()

static isCloudAvailable(): Promise<boolean>;

Tests whether or not the cloud storage is available for the provider of the default static instance. Always returns true for Google Drive. iCloud may be unavailable right after app launch or if the user is not logged in.

Returns

Promise<boolean>

A promise that resolves to true if the cloud storage is available, false otherwise.


mkdir()

static mkdir(path: string, scope?: CloudStorageScope): Promise<void>;

Creates a new directory at the given path in the provider of the default static instance.

Parameters

ParameterTypeDescription
pathstringThe directory to create.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<void>

A promise that resolves when the directory has been created.


readdir()

static readdir(
  path: string,
  scope?: CloudStorageScope,
): Promise<string[]>;

Lists the contents of the directory at the given path in the provider of the default static instance.

Parameters

ParameterTypeDescription
pathstringThe directory to list.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<string[]>

A promise that resolves to an array of file names, excluding '.' and '..'.


readFile()

static readFile(
  path: string,
  scope?: CloudStorageScope,
): Promise<string>;

Reads the contents of the file at the given path in the provider of the default static instance.

Parameters

ParameterTypeDescription
pathstringThe file to read.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<string>

A promise that resolves to the contents of the file.


rmdir()

static rmdir(
  path: string,
  options?: object,
  scope?: CloudStorageScope,
): Promise<void>;

Deletes the directory at the given path in the provider of the default static instance.

Parameters

ParameterTypeDescription
pathstringThe directory to delete.
options?{ recursive?: boolean; }Options for the delete operation. Defaults to { recursive: false }.
options.recursive?boolean-
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<void>

A promise that resolves when the directory has been deleted.


setProvider()

static setProvider(provider: CloudStorageProvider): void;

Sets the provider of the default static instance.

Parameters

ParameterTypeDescription
providerCloudStorageProviderThe provider to set.

Returns

void


setProviderOptions()

static setProviderOptions(
  options: CloudStorageProviderOptionsValue,
): void;

Sets the options for the provider of the default static instance.

Parameters

ParameterTypeDescription
optionsCloudStorageProviderOptionsValueThe options to set for the provider of the default static instance.

Returns

void


stat()

static stat(
  path: string,
  scope?: CloudStorageScope,
): Promise<CloudStorageFileStat>;

Gets the size, creation time, and modification time of the file at the given path in the provider of the default static instance.

Parameters

ParameterTypeDescription
pathstringThe file to stat.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<CloudStorageFileStat>

A promise that resolves to the CloudStorageFileStat object.


triggerSync()

iCloud
static triggerSync(
  path: string,
  scope?: CloudStorageScope,
): Promise<void>;

Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive.

Parameters

ParameterTypeDescription
pathstringThe file to trigger synchronization for.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<void>

A promise that resolves once the synchronization has been triggered.


static unlink(path: string, scope?: CloudStorageScope): Promise<void>;

Deletes the file at the given path in the provider of the default static instance.

Parameters

ParameterTypeDescription
pathstringThe file to delete.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<void>

A promise that resolves when the file has been deleted.


uploadFile()

static uploadFile(
  remotePath: string,
  localPath: string,
  options: object,
  scope?: CloudStorageScope,
): Promise<void>;

Uploads the file at the given local path to the given path in the provider of the default static instance, creating it if it doesn't exist or overwriting it if it does.

Parameters

ParameterTypeDescription
remotePathstringThe remote path to upload to.
localPathstringThe local path of the file to upload.
options{ mimeType: string; }The options for the upload. Must contain a mimeType property.
options.mimeTypestring-
scope?CloudStorageScopeThe directory scope the path is in. Defaults to set default scope set for the current provider.

Returns

Promise<void>

A promise that resolves when the file has been uploaded.


writeFile()

static writeFile(
  path: string,
  data: string,
  scope?: CloudStorageScope,
): Promise<void>;

Writes to the file at the given path in the provider of the default static instance, creating it if it doesn't exist or overwriting it if it does.

Parameters

ParameterTypeDescription
pathstringThe file to write to.
datastringThe data to write.
scope?CloudStorageScopeThe directory scope the path is in. Defaults to the default scope set for the default static instance.

Returns

Promise<void>

A promise that resolves when the file has been written.

On this page