fs readFilesync错误路径必须是一个字符串

时间:2016-08-03 09:53:43

标签: javascript node.js

我有一个上传文件的代码 这里是代码:

            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);

但该文件已成功上传,如何修复?谢谢

1 个答案:

答案 0 :(得分:1)

尝试强制进行字符串转换:

SELECT DISTINCT City FROM Customers;