Skip to main content

Getting started with React Native OMH Storage

React Native OMH Storage is a project that integrates various cloud storage providers to React Native. It offers a unified API to work with different storage providers.

Prerequisites​

Before getting started, the documentation assumes you are able to create a project with React Native. If you do not meet these prerequisites, follow the links below:

React Native - Setting up the development environment

Additionally, the current versions of the Android OMH libraries require a minimum Android API level of 23 or 26 depending on chosen provider. To ensure your Android application builds successfully, set the minSdkVersion to at least 23 for Google Drive and Dropbox, or 26 for OneDrive, in your android/build.gradle file, depending on the storage providers you plan to support.

Installation​

To integrate a storage provider into your React Native project, follow the specific steps for each provider:

Usage​

GOOD TO KNOW

Operations that can be performed on files can also be applied to folders.

Note:

Below examples are referencing storageClient. You can see example initialization and usage in our Example App. Please refer to getStorageClient and useRequireStorageClient files for example implementation.

Get root folder path​

Retrieve the root folder ID of the storage service. Useful for listing files in the root folder.

const rootFolderId = storageClient.rootFolderId;

List files​

List files in a specific folder.

const files = await storageClient.listFiles('folderId');

Search files​

Search for files with names containing the specified query.

const searchResults = await storageClient.search('fileName');

Create folder​

Create a folder in a specific folder.

const newFolder = await storageClient.createFolder(
'folderName',
'parentFolderId'
);

Create file (with mime type)​

Create a file with a specified MIME type in a folder.

const newFile = await storageClient.createFileWithMimeType(
'fileName',
'fileMimeType',
'parentFolderId'
);

Create file (with extension)​

Create a file with a specified extension in a folder.

const newFile = await storageClient.createFileWithExtension(
'fileName',
'fileExtension',
'parentFolderId'
);

Update file​

Update a file with the content of a local file.

const updatedFile = await storageClient.updateFile(localFile, 'fileId');

Delete file​

Move a file to trash using its ID.

await storageClient.deleteFile('fileId');

Permanently Delete File​

Permanently delete a file using its ID.

await storageClient.permanentlyDeleteFile('fileId');

Upload file​

Upload a local file to a specific folder.

const uploadedFile = await storageClient.localFileUpload(localFile, 'folderId');

Download file​

Download a file using its ID.

await storageClient.downloadFile(file, 'saveDirectory');

Export file​

Export a file with a specific MIME type.

await storageClient.exportFile(
file,
'mimeType',
'fileExtension',
'saveDirectory'
);

Get file metadata​

Retrieve the metadata of a file using its ID.

const fileMetadata = await storageClient.getFileMetadata('fileId');

For more details on file metadata support for each provider, please refer to the File metadata documentation.

Get file versions​

Retrieve versions of a file using its ID.

const fileVersions = await storageClient.getFileVersions('fileId');

Download file version​

Download a specific version of a file.

await storageClient.downloadFileVersion(file, 'versionId', 'saveDirectory');

Get file permissions​

List the permissions of a file using its ID.

const permissions = await storageClient.getPermissions('fileId');

For more details on file permissions support for each provider, please refer to the File permissions documentation.

Create file permission​

Create a permission for a file.

const newPermission = await storageClient.createPermission(
'fileId',
'role', // e.g., 'writer'
{ email: 'user@example.com' }, // Permission recipient
true, // Send notification email
'Optional message'
);

Update file permission​

Update the role of a permission for a file.

const updatedPermission = await storageClient.updatePermission(
'fileId',
'permissionId',
'newRole' // e.g., 'reader'
);

Delete file permission​

Delete a permission for a file.

await storageClient.deletePermission('fileId', 'permissionId');

Get file url​

Retrieve the URL of a file.

const fileUrl = await storageClient.getWebUrl('fileId');

For a more in depth view on the available methods, access the Reference API.

Sample app​

Explore the sample app included in the repository to see the implementation of storage with Google Drive and other storage providers. The sample app demonstrates the integration and usage of the various storage providers, providing a practical example to help you get started quickly.