Reputation: 1436
i have a code for uploading file here the code :
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)
}
and showing error like this : uncaughtException TypeError: path must be a string
refers to var data = fs.readFileSync(oriPath.path);
but the file is successfuly uploaded, how to fix that? thank you
Upvotes: 0
Views: 713
Reputation: 2150
try to force string conversion:
var data = fs.readFileSync(String(oriPath.path))
Upvotes: 1