在cloudinary中,我有一个名为images的文件夹,我想将文件上传到该文件夹中。我已经完成了 cloudinary 配置的设置。存储选项和文件过滤器已经完成。在请求中,我发送了将文件上传到 cloudinary 的 post 请求,但不上传到文件夹。如何将文件上传到 Cloudinary 中的某个文件夹?
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, './images/');
},
filename: (req, file, cb) => {
cb(null, new Date().toISOString().replace(/:/g, '-') + file.originalname);
}
});
const fileFilter = (req, file, cb) => {
if (!file.mimetype.match(/jpe|jpeg|png|gif$i/)) {
cb(new Error('File is not supported'), false);
return;
}
cb(null, true);
};
const upload = multer({
storage,
fileFilter
});
router.post('/', upload.single('profileImage'), async (req,res) => {
const result = await cloudinary.v2.uploader.upload(req.file.path);
})
Run Code Online (Sandbox Code Playgroud)