Reputation: 43
I am trying to open a local file and create a File
object from an image file using the following code
var newFileObj = new File([buffer],fileObj.originalname,{type: fileObj.mimetype});
However this gives me File is undefined. I am using nodejs v7.0.0
Do i need to require any file before for using File type?
P.S- This is a REST API , there is no html involved.
Upvotes: 2
Views: 3339
Reputation: 1652
You need to use 'fs' for read/write file in node world. Here is the link
https://nodejs.org/api/fs.html
fs.open('myfile', 'r', (err, fd) => {
if (err) {
if (err.code === 'ENOENT') {
console.error('myfile does not exist');
return;
}
throw err;
}
readMyData(fd);
});
Upvotes: 1