Skip to content

SoluLab/s3-upload-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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',
	});
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published