1.2.0 • Published 2 years ago

s3-upload-helper v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

S3 Uplod Library


Install


To use the package, just do the standard

$ npm install --save s3-upload-helper

Startup


  • CommonJS
var S3Helper = require('s3-upload-helper');

var s3 = new S3Helper('accessId', 'secretKey', 's3BucketName', 's3Region');
  • ESM
import S3Helper  from 's3-upload-helper';

const s3 = new S3Helper('accessId', 'secretKey', 's3BucketName', 's3Region');

Usage


  • uploadFileS3
/* It Returns a Multer instance that provides several methods for generating middleware, that process files uploaded in multipart/form-data format.

* in the example below i have used .array() function that returns array or files in req.files

* you can use other functions like .any, .fields .none and .single

* all these functions returns a middleware that will process your file upload

* all these functions returns uploaded file in different way you can go through multer docs for that

* pass fileName inside req body for naming your file 

* if not passed, file name would be "File/File-current_time.extension"

* file will be available on req.files as array of fles

*/
router.post('/upload-file', s3.uploadFileS3.array('file'), (req, res) => {
	const file = req.files; // Array of files
	if (file) {
		return res.status(200).send({ data: file });
	}
	res.status(500).send({ errMsg: 'Something went wrong, file not uploaded' });
});
  • S3ExtractMeta
router.post('/extract-file-metadata', (req, res) => {
	// pass file as array of objects
	const file = req.files;
	const metaData = s3.S3ExtractMeta(file);
	if (metaData) {
		return res.status(200).send({ data: metaData });
	}

	res.status(500).send({
		errMsg: 'Something went wrong',
	});
});
1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago