作者:有风吹过best | 2023-09-11 13:01
1> Pradeep Sain..:
var express = require( 'express' ),
router = express.Router(),
util = require( 'util' ),
multer = require( 'multer' );
var storage = multer.diskStorage(
{
destination: './uploads/',
filename: function ( req, file, cb ) {
//req.body is empty...
//How could I get the new_file_name property sent from client here?
cb( null, file.originalname+ '-' + Date.now()+".pdf");
}
}
);
var upload = multer( { storage: storage } );
router.route( '/upload' )
.post( upload.single( 'file' ), post );
function post( request, response ) {
response.json( { message: 'Files Uploaded!' } );
}
尽管此代码可以回答问题,但提供有关如何和/或为什么解决问题的其他上下文将提高答案的长期价值。