CloudStorage
Constructors
Constructor
new CloudStorage(
provider?: CloudStorageProvider,
options?: CloudStorageProviderOptionsValue,
): RNCloudStorage;Creates a new RNCloudStorage instance for the given provider.
Parameters
| Parameter | Type | Description |
|---|---|---|
provider? | CloudStorageProvider | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to append to. |
data | string | The data to append. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to trigger synchronization for. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
remotePath | string | The remote path of the file to download from the cloud. |
localPath | string | The local path to download the cloud file to. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The path to test. |
scope? | CloudStorageScope | The 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
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
| Parameter | Type | Description |
|---|---|---|
path | string | The directory to create. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The directory to list. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to read. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The directory to delete. |
options? | { recursive?: boolean; } | Options for the delete operation. Defaults to { recursive: false }. |
options.recursive? | boolean | - |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
provider | CloudStorageProvider | The provider to set. |
Returns
void
setProviderOptions()
setProviderOptions(
options: CloudStorageProviderOptionsValue,
): void;Sets the options for the current provider.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | CloudStorageProviderOptionsValue | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to stat. |
scope? | CloudStorageScope | The 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
| Parameter | Type |
|---|---|
listener | (available: boolean) => void |
Returns
void
triggerSync()
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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to trigger synchronization for. |
scope? | CloudStorageScope | The 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()
unlink(path: string, scope?: CloudStorageScope): Promise<void>;Deletes the file at the given path.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | The file to delete. |
scope? | CloudStorageScope | The 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
| Parameter | Type |
|---|---|
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
| Parameter | Type | Description |
|---|---|---|
remotePath | string | The remote path to upload to. |
localPath | string | The local path of the file to upload. |
options | { mimeType: string; } | The options for the upload. Must contain a mimeType property. |
options.mimeType | string | - |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to write to. |
data | string | The data to write. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to append to. |
data | string | The data to append. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to trigger synchronization for. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
remotePath | string | The remote path of the file to download from the cloud. |
localPath | string | The local path to download the cloud file to. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The path to test. |
scope? | CloudStorageScope | The 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
The default CloudStorageProvider.
getProvider()
static getProvider(): CloudStorageProvider;Gets the current provider of the default static instance.
Returns
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
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
| Parameter | Type | Description |
|---|---|---|
path | string | The directory to create. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The directory to list. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to read. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The directory to delete. |
options? | { recursive?: boolean; } | Options for the delete operation. Defaults to { recursive: false }. |
options.recursive? | boolean | - |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
provider | CloudStorageProvider | The provider to set. |
Returns
void
setProviderOptions()
static setProviderOptions(
options: CloudStorageProviderOptionsValue,
): void;Sets the options for the provider of the default static instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | CloudStorageProviderOptionsValue | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to stat. |
scope? | CloudStorageScope | The 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()
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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to trigger synchronization for. |
scope? | CloudStorageScope | The 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.
unlink()
static unlink(path: string, scope?: CloudStorageScope): Promise<void>;Deletes the file at the given path in the provider of the default static instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | The file to delete. |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
remotePath | string | The remote path to upload to. |
localPath | string | The local path of the file to upload. |
options | { mimeType: string; } | The options for the upload. Must contain a mimeType property. |
options.mimeType | string | - |
scope? | CloudStorageScope | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The file to write to. |
data | string | The data to write. |
scope? | CloudStorageScope | The 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.