A simple Node.js SDK for interacting with the File Browser API. This SDK supports authentication, folder management, file uploading, and other file management functionalities.
Note: This SDK is unofficial and is not officially maintained by the File Browser project. Additionally, this SDK is currently under development and should not be used in production. It may have bugs and incomplete features.
- Log in using a username and password to get an authentication token.
- Create and delete folders.
- Upload files to specific folders with name support.
- Rename files.
- Get sharable links for files.
- Easy integration with your Node.js projects.
You can install this SDK via npm:
npm install file-browser-nodejs
First, import and initialize the FileBrowserSDK
class. You will need to provide the base API URL for your File Browser instance.
const FileBrowserSDK = require("file-browser-nodejs");
const sdk = new FileBrowserSDK("http://your-file-browser-instance.com"); // Replace with your File Browser URL
To authenticate and get an authentication token, use the authenticate
method. This method requires a username and password.
const username = "your_username"; // Replace with your username
const password = "your_password"; // Replace with your password
sdk
.authenticate(username, password)
.then(() => {
console.log("Authenticated successfully");
})
.catch((err) => {
console.error("Authentication failed:", err);
});
To create a folder, use the createFolder
method. You need to provide the folder path where the folder should be created.
const folderPath = "path/to/folder";
sdk
.createFolder(folderPath)
.then((data) => {
console.log("Folder created:", data);
})
.catch((err) => {
console.error("Error creating folder:", err);
});
To delete a folder, use the deleteFolder
method. Provide the path of the folder to be deleted.
const folderPath = "path/to/folder";
sdk
.deleteFolder(folderPath)
.then(() => {
console.log("Folder deleted successfully");
})
.catch((err) => {
console.error("Error deleting folder:", err);
});
To upload a file, you need to provide the file's path and the destination folder path. The SDK handles file uploads by chunking and performing all necessary HTTP requests.
const filePath = "path/to/your/file"; // Path to the file you want to upload
const folderPath = "destination/folder"; // Destination folder path
sdk
.uploadFile(filePath, folderPath)
.then((response) => {
console.log("File uploaded successfully:", response);
})
.catch((err) => {
console.error("Upload failed:", err);
});
To rename a file, use the renameFile
method. Provide the current file name and the new file name, along with the folder path.
const folderPath = "path/to/folder";
const currentFileName = "old_file.txt";
const newFileName = "new_file.txt";
sdk
.renameFile(folderPath, currentFileName, newFileName)
.then((response) => {
console.log("File renamed successfully:", response);
})
.catch((err) => {
console.error("Error renaming file:", err);
});
To generate a sharable link for a file, use the getSharableLink
method. Provide the file path for which you want to generate the link.
const filePath = "path/to/your/file";
sdk
.getSharableLink(filePath)
.then((linkData) => {
if (linkData) {
console.log("Sharable link generated:", linkData.url);
console.log("Download link:", linkData.downloadLink);
} else {
console.log("No sharable link available.");
}
})
.catch((err) => {
console.error("Error generating sharable link:", err);
});
To fetch details of a specific file or folder, use the getFileDetails
method. Provide the file or folder path.
const filePath = "path/to/your/file";
sdk
.getFileDetails(filePath)
.then((details) => {
console.log("File details:", details);
})
.catch((err) => {
console.error("Error fetching file details:", err);
});
To list the files or folders in a specific folder, use the getFilesInFolder
method. Provide the folder path.
const folderPath = "path/to/folder";
sdk
.getFilesInFolder(folderPath)
.then((files) => {
console.log("Files in folder:", files);
})
.catch((err) => {
console.error("Error fetching files:", err);
});
We welcome contributions to this project. If you want to help, please fork the repository and submit a pull request.
- Fork the repo.
- Create a new branch for your feature or bug fix.
- Make changes and commit them.
- Push your branch and create a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions or issues, please open an issue on GitHub.