我有一个上传文件的代码 这里是代码:
var oriPath = JSON.stringify(req.files.profilePicture);
var data = fs.readFileSync(oriPath.path);
var ext = path.extname(oriPath.name);
if (!ext) {
return next(err);
}
var newName = Date.now().toString() + ext;
var path = config.fullhostname + config.uploadDir + newName;
if (!fs.writeFileSync(path, data)) {
return next("Failed to upload image", 400)
}
并显示如下错误:uncaughtException TypeError: path must be a string
引用var data = fs.readFileSync(oriPath.path);
但该文件已成功上传,如何修复?谢谢
答案 0 :(得分:1)
尝试强制进行字符串转换:
SELECT DISTINCT City FROM Customers;