test-filer v1.1.2
Filer (File System as a Service)
File Management As A Service is a a generic package that handles all the operations that are required to upload, download and delete files from cloud storage buckets.
Main Functionalities are
Installation
npm i filer
In Node.js:
import Filer from 'lf-filer';
Using Filer
import Filer from 'lf-filer';
const filer = new Filer();
Configuration
Filer can be configured using a configuration file.
Using configuration file
The configuration file can be set using the following file structure.
export const filerConfig = {
dbProvider: '', // 'dynamodb' available (optional)
dbProviderConfig: {
// optional if dbProvider is not set
region: '', // aws region
credentials: {
accessKeyId: '', // aws accessKeyId
secretAccessKey: '' // aws secretAccessKey
},
tableName: '' // database table name
},
storageProvider: '', // 's3' available
storageProviderConfig: {
accessKeyId: '', // aws accessKeyId
bucket: '' // s3 bucket name
},
restrictions: {
// file upload restrictions
maxFileSizeInMB: 25,
minFileSizeInMB: 0.1,
restrictedExtensions: ['exe', 'pdf']
},
logger: (message): void => {} //custom logger function
};
The file can be imported and used with Filer.
import Filer from 'lf-filer';
import { filerConfig } from './filerConfig';
const filer = new File(filerConfig);
Features
delete()
Delete the file from S3 bucket and deletes the file metadata from DB.
delete(bucket: string, key: string): Promise<{ message: unknown; success: boolean }>
deleteDirectoryContent()
BULK delete the file from S3 bucket within a folder
deleteDirectoryContent(bucket: string, path: string): Promise<any>
deleteMultipleFiles()
Bulk delete the file from S3 bucket and deletes the file metadata from DB.
deleteMultipleFiles(bucket: string, keys: string[]):
Promise<
{
message: unknown;
success: boolean
}[]
| { message: unknown; success: boolean }
>
download()
Download the file from S3 bucket
download(bucket: string, key: string, downloadPath: string):
Promise<
{
data: {
contentLength: any;
contentType: any;
downloadPath: string;
etag: any;
key: string;
lastModified: any
}[];
message: undefined;
success: boolean
}
| { data: undefined; message: unknown; success: boolean }
>
downloadDirectoryContent()
BULK download the files from S3 bucket within a folder
downloadDirectoryContent(bucket: string, path: string, localDownloadPath: string): Promise<any>
downloadMultipleFiles()
Bulk download the file from S3 bucket
downloadMultipleFiles(bucket: string, keys: string[], downloadPath: string):
Promise<
(
{
data: {
contentLength: any;
contentType: any;
downloadPath: string;
etag: any;
key: string;
lastModified: any
}[];
message: undefined;
success: boolean
}
| { data: undefined; message: unknown; success: boolean }
)[]
| { message: unknown; success: boolean}
>
getObject()
Get the database metadata for the file
getObject(Key: string): Promise<any>
getSignedURI()
Get signed url for the file. If signed url is not available, it will return the file url.
getSignedURI(bucket: string, key: string):
Promise<
{
data: {
url: any
}[];
message: string;
success: boolean
}
| { data: undefined; message: unknown; success: boolean }
>
listAllFiles()
List all files and folders in the bucket
listAllFiles(bucket: string, path: string):
Promise<
{
data: any;
message: undefined;
success: boolean
}
|
{ data: undefined; message: unknown; success: boolean }
>
upload()
Upload the file to S3 bucket and save the file metadata to DB
upload(bucket: string, key: string, file: any):
Promise<
{ data:
{
Bucket: any;
ETag: any;
Key: any;
Location: any;
derivedName: string;
extension: string;
fileName: string;
fileType: string;
filesize: number | false;
mime: string | false
};
message: string;
success: boolean
}
| { data: undefined; message: unknown; success: boolean }
>
uploadDirectoryContent()
Bulk upload directory to S3 bucket and save the file metadata to DB
uploadDirectoryContent(bucket: string, path: string):
Promise<
(
{
data: {
Bucket: any;
ETag: any;
Key: any;
Location: any;
derivedName: string;
extension: string;
fileName: string; f
ileType: string;
filesize: number | false;
mime: string | false
};
message: string;
success: boolean
}
| { data: undefined; message: unknown; success: boolean }
)[]
| { message: unknown; success: boolean }
>
uploadMultipleFiles()
Bulk upload the file to S3 bucket and save the file metadata to DB
uploadMultipleFiles(bucket: string, files: { filePath: string; key: string }[]):
Promise<
(
{
data: {
Bucket: any;
ETag: any;
Key: any;
Location: any;
derivedName: string;
extension: string;
fileName: string;
fileType: string;
filesize: number | false;
mime: string | false
};
message:
string; success: boolean
}
| { data: undefined; message: unknown; success: boolean }
)[]
| { message: unknown; success: boolean }
>