Skip to content

upload file save as hash that wraps around multer,the file name will also with height and width if is image

Notifications You must be signed in to change notification settings

ljwrer/multer-hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multer-hash

upload file save as hash that wraps around multer,the file name will also with height and width if is image

Installation

npm install multer-hash

Usage

const multerHash = require('multer-hash');
const app = require('express')();
const uploader = multerHash(config,function(err,req,res,next){
	
})
app.post('/yourpath',uploader)

config

same as multer:

  • dest
  • limits
  • field(default as Filedata)

fileFilter

same as multer,also support file extension array

{
	fileFilter:['jpg','png']
}

cachePath

a cachePath for save file to calculate file hash and image size,will choose system cache path if not specify

result handling

get file path with hashed name in req.publicPath

const multerHash = require('multer-hash');
const uploader = multerHash(config,function(err,req,res,next){
	if(err){
		// handle err
	}else{
		const publicPath = req.publicPath;
		// handle result
	}
})

error handling

specify error code:

	ERROR_CODE = {
	  'IO': 'IO',
	  'INVALID_IMAGE': 'INVALID_IMAGE',
	  'LIMIT_FILE_SIZE': 'LIMIT_FILE_SIZE',
	  'LIMIT_UNEXPECTED_FILE': 'LIMIT_UNEXPECTED_FILE',
	  'UNKNOWN': 'UNKNOWN',
	}

###exmaple

const multerHash = require('multer-hash');
const ERROR_CODE = multerHash.ERROR_CODE;
const uploader = multerHash(config,function(err,req,res,next){
	if(err){
		const errorCode = err.code;
		if(errorCode === ERROR_CODE.IO){
			//handle your io error
		}
	}
})

About

upload file save as hash that wraps around multer,the file name will also with height and width if is image

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published