@voicenter-team/aws-uploader
v1.0.10
Published
The helper that will upload your files to AWS!
Downloads
76
Readme
title: Getting started description: The VoicenterTeam AWS-Uploader is a lightweight and simple utility to upload directories to AWS S3, built specifically for Node.js applications. navigation: title: Getting Started
@voicenter-team/aws-uploader
A lightweight and simple utility to upload directories to AWS S3, built specifically for Node.js applications. It helps to upload your project artifacts, like distribution folders, to S3 with just a few lines of code. This package is built by the Voicenter Team for community use.
Installation
Use the package manager npm to install @voicenter-team/aws-uploader.
npm install @voicenter-team/aws-uploader
Usage
Here is a simple example of using @voicenter-team/aws-uploader:
import { Uploader } from '@voicenter-team/aws-uploader'
const uploader = new Uploader({
region: 'your-aws-region',
credentials: {
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key'
}
})
uploader.proceedUploadDirectory(
'your-bucket-name',
'./local-directory-path',
'target-directory-name'
)
.then(() => console.log('Upload finished'))
.catch(err => console.error('Upload error:', err))
Configuration
The Uploader constructor takes an AWSConfig object as parameter:
region
: AWS region.credentials
: Object containingaccessKeyId
andsecretAccessKey
.silent
: (Optional) If true, the Uploader won't log anything. Default value istrue
.logger
: (Optional) A custom logger object that should havelog
,error
, andwarn
methods.
Using Custom Logger
You can pass a custom logger to the Uploader
constructor. The logger object must have log
, error
, and warn
methods. Here is an example:
import { Uploader } from '@voicenter-team/aws-uploader'
const customLogger = {
log: (message, ...params) => { /* Custom log implementation */ },
error: (message, ...params) => { /* Custom error implementation */ },
warn: (message, ...params) => { /* Custom warn implementation */ }
}
const uploader = new Uploader({
region: 'your-aws-region',
credentials: {
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key'
},
silent: false,
logger: customLogger
})
By default, Uploader
uses the console as the logger. If you pass a custom logger but you want to turn off logging, you can set the silent
option to true.
Methods
proceedUploadDirectory
The proceedUploadDirectory
method uploads the contents of a local directory to the specified S3 bucket. Returns the Promise with the uploaded folder name
proceedUploadDirectory(bucketName: string, directoryPath: string, targetDir: string): Promise<string>
bucketName
: The name of the target S3 bucket.directoryPath
: The path to the local directory to upload.targetDir
: The target directory name in the S3 bucket where the files will be uploaded.
moveFiles
The moveFiles
method moves files within an S3 bucket from a source prefix to a target prefix.
moveFilesInS3(bucketName: string, sourcePrefix: string, targetPrefix: string, deleteSource: boolean): Promise<void>
bucketName
: The name of the S3 bucket.sourcePrefix
: The prefix of the source files to move.targetPrefix
: The target prefix where the files will be moved to.deleteSource
: If to delete the source folder, defaultfalse
This method is useful for scenarios where you need to reorganize or archive files within your S3 bucket, such as moving files to a specific folder or prefix.
License
MIT