node.js - node.js中如何使用memoryStorage()上传文件
问题描述
我正在学习如何在 node.js 中上传文件,当我使用 multer.diskStorage 时,我能够将文件上传到系统中的本地文件夹
const storag = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'uploads');
},
filename: (req, file, cb) => {
const { originalname } = file;
cb(null, originalname);
}
});
const upload = multer({ storage: storag });
router.post("/lecture", upload.single('file'), (req, res) => {
return res.json({ status: 'OK' });
});
但是一旦我将 multer.diskStorage 更改为 multer.memoryStorage 因为我想直接发布到谷歌云存储,服务器返回相同的路由并出现 404 错误,我想知道问题是什么
const storag = multer.memoryStorage()
const upload = multer({ storage: storag });
router.post("/lecture", upload.single('file'), instructorController.createLecture, (req, res) => {
return res.json({ status: 'OK' });
});
解决方案
推荐阅读
- python - 冲突:被其他 getUpdates 请求终止;确保只有一个机器人实例正在运行
- rust - 为什么 mpsc::Sender#send 和 mpsc::Receiver#recv 没有被标记为 mut?
- javascript - 弹出通知面板框不在右侧
- elasticsearch - 嵌套弹性搜索文档上的不同值
- python - 在 Ubuntu 上安装 Python 3.10:pip 不工作
- wordpress - 在 WooCommerce 购物车上显示含和不含增值税的总价格
- python - 如何使用 gspread 更新循环中的值,而不使用“范围”
超出网格限制” - reactjs - MUI TextField 中的 inputProps 与 InputProps
- javascript - Firebase 身份验证在页面刷新时消失
- reactjs - 使用 react-hook-form 测试包装在 TextField 中的 React 选择