multipartform-data - 上传到 Next.js API 时损坏的图像
问题描述
我正在尝试将图像作为表单数据上传到 Nextjs api 路由。我使用强大的包来解析文件并将其保存在服务器文件夹中。对于 http 请求,我在客户端使用邮递员。
这是后端代码:
import formidable from 'formidable';
export const config = {
api: {
bodyParser: false,
},
};
export default async (req, res) => {
const form = new formidable.IncomingForm();
form.on('fileBegin', (name, file) => {
file.path = "./" + file.name
});
form.parse(req, (err, fields, files) => {
console.log( files);
});
res.statusCode = 200
res.end()
};
图像 (jpeg) 保存在文件夹中。但是,它似乎已损坏或损坏。这是原始图像:
解决方案
Next.js 需要包formidable-serverless
而不是formidable
推荐阅读
- c# - 如何使用 SqlKata 从存储过程中查询?
- python - Python - 将字符串列表转换为浮点数 - 方括号和小数点导致问题
- bash - 管道 awk printf - 在(awk)格式修饰符上查找替换
- arrays - 比较两个对象列表 A 和 B 并存储在 dart 中的另一个列表 C 中
- parsing - 将一种 DSL 转换为另一种
- python-3.x - AttributeError:“LevelingSystem”对象没有属性“作者”
- sql - 从 select 语句中的列计算
- performance - 有什么方法可以估计应用程序的吞吐量(每秒处理的位数)?
- reactjs - 大型可编辑表:希望防止在修改表行时重新呈现所有行
- javascript - 如果日期是当前日期,那么它会显示任务