i tried the following two ways o fetch image from localserver in node js in face-api.js a and output of the following codes are commemnted
should i missing something or i need to try different way please help..
1st try
var image = fs.readFileSync(path);
console.log('Exists ' + typeof (image)) // Exists object
const image = await faceapi.fetchImage(image)
.then(res =>{console.log(res)})
.catch(e=> console.log("Error e "+e)) //Error e Type Error: Only absolute URLs are supported
i wanted to fetch images from loccal server and train the model but i'm not able to fetch the image. the full error is below:-
(node:25194) UnhandledPromiseRejectionWarning: TypeError: Only absolute URLs are supported
at getNodeRequestOptions (/home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/node-fetch/lib/index.js:1299:9)
at /home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/node-fetch/lib/index.js:1404:19
at new Promise (<anonymous>)
at fetch (/home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/node-fetch/lib/index.js:1401:9)
at Object.<anonymous> (/home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/tfjs-image-recognition-base/build/commonjs/dom/fetchOrThrow.js:12:42)
at step (/home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/tslib/tslib.js:136:27)
at Object.next (/home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/tslib/tslib.js:117:57)
at /home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/tslib/tslib.js:110:75
at new Promise (<anonymous>)
at Object.__awaiter (/home/milind/Desktop/FaceApi/Face-Detection-JavaScript/node_modules/tslib/tslib.js:106:16)
ps i already checked this face-api.js load image file from disk
Edit:
Repository
-temp
image.png
server.js
-Router
router.js <- here i'm having the below router code
router.post('/upload-file-face', (req, res) => {
console.log("Helllo");
Promise.all([
faceapi.nets.faceRecognitionNet.loadFromDisk('./weights'),
faceapi.nets.faceLandmark68Net.loadFromDisk('./weights'),
faceapi.nets.ssdMobilenetv1.loadFromDisk('./weights'),
]).then(async () => {
tempUpload(req,res, async(err) =>{
console.log(req.files);
if(err) {
return res.end("Error uploading file." + err);
}
var location = "./"+req.files[0].destination
var imgFile = req.files[0].filename;
if(!fs.existsSync(fspath.join(location,imgFile))) {
console.log("Not exists")
}else{
console.log('Exists') //yes Exists
}
var pp =fspath.join(location,imgFile);
console.log("path : "+pp)
const image = faceapi.fetchImage(pp)
.then(res =>{console.log(res)})
.catch(e=> console.log("Error e " +e)) // Error e TypeError: Only absolute URLs are supported
res.send("hello");
})
})
})