[英]accessing properties from javascript object
I have below object.我有以下 object。
export const multerOptions = {
storage: diskStorage({
destination: multerConfig.dest,
filename: (_req: any, file: any, cb: any) => {
/* istanbul ignore next */
cb(null, `${uuid()}${extname(file.originalname)}`);
},
}),
};
when I am printing multerOptions.storage it is returning below.当我打印 multerOptions.storage 时,它在下面返回。
diskStorage({
destination: multerConfig.dest,
filename: (_req: any, file: any, cb: any) => {
/* istanbul ignore next */
cb(null, `${uuid()}${extname(file.originalname)}`);
},
}),
.
is there anyway I can access this filename
or destination
无论如何我可以访问这个filename
或destination
This one is for single file upload这个用于单个文件上传
/**
* Module for geting image from s3 cloud server
*/
exports.upload = multer({
storage: multerS3({
s3: s3,
bucket: function (req, file, cb) {
const path = process.env.AWS_BUCKET_NAME;
cb(null, path || 'uploads/');
},
acl: 'authenticated-read',
// acl: 'public-read',
key: function (req, file, cb) {
console.log("file========", req);
// console.log(req.path.split('/')[1]);
// console.log(path.parse(file.originalname).name.replace(" ", "-"));
// console.log(Date.now() + path.parse(file.originalname).ext);
// req.path.split('/')[1] ===== Sub-Folder
// path.parse(file.originalname).name.replace(" ", "-") + Date.now() + path.parse(file.originalname).ext ===== File name
cb(null, req.path.split('/')[1]+'/'+path.parse(file.originalname).name.replace(" ", "-") + Date.now() + path.parse(file.originalname).ext);
}
})
}).single('file');
For Multiple file upload对于多个文件上传
/**
* Module for geting image from s3 cloud server
*/
exports.uploadmultiple = multer({
storage: multerS3({
s3: s3,
bucket: function (req, file, cb) {
const path = process.env.AWS_BUCKET_NAME;
cb(null, path || 'uploads/');
},
acl: 'authenticated-read',
// acl: 'public-read',
key: function (req, file, cb) {
console.log(req.path.split('/')[1]);
console.log(path.parse(file.originalname).name.replace(" ", "-"));
console.log(Date.now() + path.parse(file.originalname).ext);
// req.path.split('/')[1] ===== Sub-Folder
// path.parse(file.originalname).name.replace(" ", "-") + Date.now() + path.parse(file.originalname).ext ===== File name
cb(null, req.path.split('/')[1]+'/'+path.parse(file.originalname).name.replace(" ", "-") + Date.now() + path.parse(file.originalname).ext);
}
})
}).array('files', 2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.