Official SDK for Delta Storage
The Delta Storage SDK is a JavaScript library that provides asbtraction for interacting with the Delta Storage API. This SDK allows you to perform various operations such as reading files, uploading files, managing directories, and more.
You can install the Delta Storage SDK using your preferred package manager:
npm install --save @delta-storage/sdk
yarn add --save @delta-storage/sdk
To start using the Delta Storage SDK, you need to acquire your API_KEY from your app.delta.storage account. Once you have your API_KEY, Here's how you can get started:
import DeltaStorageSDK from '@delta-storage/sdk'
const deltaStorage = new DeltaStorageSDK({
apiKey: 'YOUR API KEY'
})
Once you've set up your instance, using the Delta Storage SDK is easy as follows:
- Directory Management
- File Management
- General
- getTotalSize (Storage Used)
- readStorage (Storage Capacity)
- readSettings
- readEncryptionKey
- verifyEncryptionKey
- updateSettings
Use the createDirectory method to create a new directory or folder.
try {
const directoryName = 'new_directory' // The name of the directory to create.
const parentDirectoryId = 'parent_directory_id_here' // The ID of the parent directory or drive.
const response = await deltaStorage.createDirectory(
directoryName,
parentDirectoryId
)
console.log(response.data) // Newly created directory details
} catch (error) {
console.error(error.message)
}
Params
directoryName
(string): The name of the new directory.parentDirectoryId
: The ID of the parent directory where the new directory will be created.
Required API Key Permission
Create Directory
Retrieve the contents of a directory by its ID. This method is useful when you want to list the directories and files within a specific directory.
try {
const directoryId = 'directory_id_here' // Replace with the desired directory ID
const response = await deltaStorage.readDirectory(directoryId)
const { directories, files } = response.data
console.log('Directories:')
directories.forEach((directory) => {
console.log(directory.name)
})
console.log('Files:')
files.forEach((file) => {
console.log(file.name)
})
} catch (error) {
console.error(error.message)
}
Params
directoryId
(string, optional): The ID of the directory you want to retrieve. If not provided, it retrieves the root directory.
Required API Key Permission
Read Directory
Use the readDirectorySize method to retrieve the total size of a directory.
try {
const directoryId = 'directory_id_here' // The ID of the directory to get the size of.
const size = await deltaStorage.readDirectorySize(directoryId)
console.log(`Total size of directory: ${size} bytes`)
} catch (error) {
console.error(error.message)
}
Params
directoryId
(string): The ID of the directory for which you want to retrieve the size.
Required API Key Permission
Read Directory
Retrieve the contents of a directory by specifying a path using segments. This method is useful when you want to navigate through directories based on a custom path.
try {
const segments = 'folder1/subfolder1/subfolder2' // Replace with your desired path
const response = await deltaStorage.readDirectoryBySegment(segments)
const { directories, files } = response.data
console.log('Directories:')
directories.forEach((directory) => {
console.log(directory.name)
})
console.log('Files:')
files.forEach((file) => {
console.log(file.name)
})
} catch (error) {
console.error(error.message)
}
Params
segments
(string): A custom path to the directory, where segments are separated by slashes ('/'). Specify the path to the directory you want to retrieve.
Required API Key Permission
Read Directory
Use the move method to move files and directories to a new parent directory.
try {
const newParentId = 'new_parent_directory_id' // The ID of the new parent directory.
const childrenIds = ['child_directory_id_1', 'child_directory_id_2'] // An array of child directory IDs to move.
const childrenFileIds = ['child_file_id_1', 'child_file_id_2'] // (optional) An array of child file IDs to move.
await deltaStorage.move(parentId, childrenIds, childrenFileIds)
console.log('Files and directories moved successfully.')
} catch (error) {
console.error(error.message)
}
Params
newParentId
(string): The ID of the new parent directory where the child directories/files will be moved.childDirectoryIds
(string[]): An array of child directory IDs to move.childFileIds
(string[], optional): An array of child file IDs to move (if applicable).
Required API Key Permission
Create Directory
Delete Directory
Use the getDirectoryAsZip method to retrieve a directory in Delta Storage as a compressed ZIP archive.
try {
const directoryId = 'directory_id_here' // The ID of the directory to retrieve as a ZIP archive.
const zipFileName = 'retrieved_directory' // The name of the ZIP file to save on the client side.
const result = await deltaStorage.getDirectoryAsZip(directoryId, zipFileName)
if (result.success) {
console.log(`Directory retrieved as ZIP: ${zipFileName}.zip`)
} else {
console.error('Failed to retrieve the directory as a ZIP file.')
}
} catch (error) {
console.error(error.message)
}
Params
directoryId
- The ID of the directory to be zipped and downloaded.zipFileName
- The name of the downloaded ZIP file (excluding the ".zip" extension).
Required API Key Permission
Read Directory
Use the downloadDirectoryAsZip method to download the contents of a directory as a compressed ZIP archive.
try {
const directoryId = 'directory_id_here' // The ID of the directory to be zipped and downloaded.
const zipFileName = 'downloaded_directory' // The name of the downloaded ZIP file.
const result = await deltaStorage.downloadDirectoryAsZip(
directoryId,
zipFileName
)
if (result.success) {
console.log(`Downloaded ZIP file: ${zipFileName}.zip`)
} else {
console.error('Failed to download the directory as a ZIP file.')
}
} catch (error) {
console.error(error.message)
}
Params
directoryId
- The ID of the directory to be zipped and downloaded.zipFileName
- The name of the downloaded ZIP file (excluding the ".zip" extension).
Required API Key Permission
Read Directory
Use the renameDirectory method to rename a directory.
try {
const directoryId = 'directory_id_here' // The ID of the directory to rename.
const newName = 'new_directory_name' // The new name for the directory.
await deltaStorage.renameDirectory(directoryId, newName)
console.log(`Directory renamed to: ${newName}`)
} catch (error) {
console.error(error.message)
}
Params
directoryId
- The ID of the directory you want to rename.newName
- The new name for the directory.
Required API Key Permission
Create Directory
orDelete Directory
Use the deleteDirectory method to delete a directory.
try {
const directoryId = 'directory_id_here' // The ID of the directory to delete.
await deltaStorage.deleteDirectory(directoryId)
console.log(`Directory with ID ${directoryId} has been deleted.`)
} catch (error) {
console.error(error.message)
}
Params
directoryId
- The ID of the directory you want to delete.
Required API Key Permission
Delete Directory
Use the uploadFile method to upload a file.
try {
const file = /* your file data */; // Your file input or Blob.
const directoryId = 'directory_id_here'; // The ID of the target directory.
const storageClasses = ['class1', 'class2']; // An array of storage classes (optional).
const response = await deltaStorage.uploadFile(file, directoryId, storageClasses);
console.log(response.data); // Uploaded file details
} catch (error) {
console.error(error.message);
}
Params
file
(formData): The file data to be uploaded.directoryId
(string): The ID of the target directory.storageClasses
(string[], optional): An array of storage classes. (hot, warm, glacier)
Required API Key Permission
Upload File
Use the uploadFiles method to upload multiple files.
try {
const files = [
{
file: /* file_data_1 */,
directoryId: 'directory_id_1',
storageClasses: ['class1', 'class2']
},
{
file: /* file_data_2 */,
directoryId: 'directory_id_2'
},
// Add more file objects as needed
];
await deltaStorage.uploadFiles(files);
console.log('Files uploaded successfully');
} catch (error) {
console.error(error.message);
}
Params
files
(array): An array of objects, each containing the properties for file uploads, includingfile
,directoryId
, andstorageClasses
(optional).
Required API Key Permission
Upload File
Use the readFile method to retrieve the contents of a file by its ID.
try {
const fileId = 'file_id_here' // The ID of the file you want to read.
const response = await deltaStorage.readFile(fileId)
console.log(response.data) // The file contents
} catch (error) {
console.error(error.message)
}
Params
fileId
(string, optional): The ID of the file you want to retrieve. If not provided, it retrieves all your files.
Required API Key Permission
Read File
Use the renameFile method to rename a file.
try {
const fileId = 'file_id_here' // The ID of the file to rename.
const newName = 'new_file_name.txt' // The new name for the file.
await deltaStorage.renameFile(fileId, newName)
console.log(`File renamed to: ${newName}`)
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file you want to rename.newName
(string): The new name for the file.
Required API Key Permission
Upload File
orDelete File
Use the updateFile method to update information about a file
try {
const fileId = 'file_id_here' // The ID of the file to update.
const newName = 'new_file_name.txt' // The new name for the file (optional).
const additionalClasses = ['class1', 'class2'] // Additional storage classes (optional).
const removalClasses = ['class3', 'class4'] // Storage classes to remove (optional).
await deltaStorage.updateFile(
fileId,
newName,
additionalClasses,
removalClasses
)
console.log('File information updated successfully')
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file you want to rename.newName
(string, optional): The new name for the file.addStorageClasses
(string[], optional): An array of additional - storage classes.removeStorageClasses
(string[], optional): An array of storage classes to remove.
Required API Key Permission
Upload File
orDelete File
Use the deleteFile method to delete a file.
try {
const fileId = 'file_id_here' // The ID of the file to delete.
await deltaStorage.deleteFile(fileId)
console.log(`File with ID ${fileId} has been deleted.`)
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file you want to delete.
Required API Key Permission
Delete File
Use the addFileAccess method to enable file protection via password or invite-only via emails.
try {
const fileId = 'file_id_here' // The ID of the file to grant access to.
const cid = 'content_identifier_here' // The CID for acccessing the file.
const accessInfo = {
email: '[email protected]', // The email of the user you want to grant access to (optional).
password: 'access_password' // The password to access the file (optional).
}
const result = await deltaStorage.addFileAccess(fileId, cid, accessInfo)
console.log(`Access granted to file ID ${fileId} with CID ${cid}`)
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file you want to grant access to.cid
(string): The content identifier (CID) for accessing the file.accessInfo
(object): An object containing access information, including an optionalemail
andpassword
.
Required API Key Permission
Upload File
Use the readFileAccess method to retrieve access information for a specific file identified by a content identifier (CID).
try {
const fileId = 'file_id_here' // The ID of the file for which you want to retrieve access information.
const cid = 'content_identifier_here' // The content identifier (CID) for accessing the file.
const accessInfo = await deltaStorage.readFileAccess(fileId, cid)
console.log('Access Information:', accessInfo)
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file for which you want to retrieve access information.cid
(string): The content identifier (CID) for accessing the file.
Required API Key Permission
Read File
Use the verifyFileAccessPassword method to verify the password for accessing a specific file identified by a content identifier (CID).
try {
const fileId = 'file_id_here' // The ID of the file for which you want to verify access.
const cid = 'content_identifier_here' // The content identifier (CID) for accessing the file.
const accessInfo = {
password: 'access_password' // The password to verify.
}
const verificationResult = await deltaStorage.verifyFileAccessPassword(
fileId,
cid,
accessInfo
)
if (verificationResult.accessGranted) {
console.log('Access granted.')
} else {
console.log('Access denied.')
}
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file for which you want to verify access.cid
(string): The content identifier (CID) for accessing the file.accessInfo
(object): An object containing the accesspassword
to verify.
Required API Key Permission
Upload File
Use the updateFileAccess method to modify access settings for a specific file.
try {
const fileId = 'file_id_here' // The ID of the file for which you want to modify access settings.
const cid = 'content_identifier_here' // The content identifier (CID) for accessing the file.
const accessSettings = {
secureSharing: 'PUBLIC' // The desired access setting: 'PUBLIC', 'PASSWORD', or 'RESTRICTED'.
}
const updateResult = await deltaStorage.updateFileAccess(
fileId,
cid,
accessSettings
)
console.log('Access settings updated successfully.')
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file for which you want to verify access.cid
(string): The content identifier (CID) for accessing the file.accessSettings
(object): An object containing the desired access setting (secureSharing can be 'PUBLIC', 'PASSWORD', or 'RESTRICTED').
Required API Key Permission
Upload File
Use the deleteFileAccess method to remove access to a specific file.
try {
const fileId = 'file_id_here' // The ID of the file for which you want to remove access.
const cid = 'content_identifier_here' // The content identifier (CID) for accessing the file.
const accessInfo = {
email: '[email protected]', // The email of the user to remove access from.
deleteAll: true // (optional) Set to `true` to delete all access, or `false` to remove access for a specific user.
}
const deleteResult = await deltaStorage.deleteFileAccess(
fileId,
cid,
accessInfo
)
console.log('Access removed successfully.')
} catch (error) {
console.error(error.message)
}
Params
fileId
(string): The ID of the file for which you want to verify access.cid
(string): The content identifier (CID) for accessing the file.accessInfo
(object): An object containing the email of the user from whom you want to remove access and an optional deleteAll flag.
Required API Key Permission
Upload File
Use the getTotalSize method to retrieve the total storage size used by authenticated user.
try {
const storageSize = await deltaStorage.getTotalSize()
console.log('Total storage size used:', storageSize, 'bytes')
} catch (error) {
console.error(error.message)
}
Required API Key Permission
Read Directory
Use the readStorage method to retrieve information about the storage capacity of authenticated user.
try {
const storageInfo = await deltaStorage.readStorage()
console.log('Storage Capacity:', storageInfo.capacity, 'bytes')
console.log('Storage Used:', storageInfo.used, 'bytes')
} catch (error) {
console.error(error.message)
}
Required API Key Permission
Read Directory
This method allows you to retrieve user-specific settings and account information, such as whether the user is in secured mode, the edge node they are using, and more.
try {
const userSettings = await deltaStorage.readSettings()
console.log('User Settings:', userSettings)
} catch (error) {
console.error(error.message)
}
This allows you to retrieve the encryption key used for secure data access in your Delta Storage account.
try {
const encryptionKey = await deltaStorage.readEncryptionKey()
console.log('Encryption Key:', encryptionKey)
} catch (error) {
console.error(error.message)
}
This allows you to verify an encryption key associated with your Delta Storage account. The result indicates whether the provided key is valid or not.
try {
const providedEncryptionKey = 'your_encryption_key_here' // The encryption key to verify.
const verificationResult = await deltaStorage.verifyEncryptionKey(
providedEncryptionKey
)
if (verificationResult.isValid) {
console.log('Encryption Key is valid.')
} else {
console.log('Encryption Key is not valid.')
}
} catch (error) {
console.error(error.message)
}
This allows you to modify user-specific settings for your Delta Storage account, including the edge node, encryption key, and secured mode.
try {
const updatedSettings = {
node: 'new_edge_node', // (optional) Specify a new edge node.
encryptionKey: 'new_encryption_key', // (optional) Set a new encryption key.
isSecureMode: true // (optional) Enable or disable secured mode (true or false).
}
const updateResult = await deltaStorage.updateSettings(updatedSettings)
console.log('User settings updated successfully.')
} catch (error) {
console.error(error.message)
}
Params
body
(object): An object containing the user-specific settings to update (node, encryptionKey, isSecureMode).
Problem: Unauthorized error when performing an operation.
Solution: Ensure that your API key has the necessary permissions for the operation you're trying to perform.