- Used for uploading files to AWS S3.
- Files are resized according to user-defined dimensions.
- Package uses pnpm as the package manager.
npm i mantiqh-resizer-js
import { resizeAndUpload } from 'mantiqh-resizer-js'
// your backend code...
// File buffer received from multer
const fileBuffer = req.file.buffer
// Output key for storage location in S3
const outputKey = `uploads/${Date.now()}-${req.file.originalname}`
// Resize and upload to S3
const imageUrl = await resizeAndUpload(fileBuffer, 300, 300, outputKey)
console.log('Image URL:', imageUrl) // Returns a CloudFront URL
// your backend code...
After execution, you will receive a URL from AWS CloudFront.
Ensure you have the following AWS credentials set in a .env
file:
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
S3_BUCKET=your-bucket-name
CLOUDFRONT_DOMAIN=your-cloudfront-domain