I am trying to use the Hikvision device DS-K1T341AMF.
Could you please guide me on how to upload a face image and link it to the correct person on this device?
I have already created a person using the following API:
POST /ISAPI/AccessControl/UserInfo/Record?format=json
I am currently trying to upload a JPG image, but it is not working.
Could you please let me know what I am missing?
async uploadFaceDataBinaryType(memberData, service) {
try {
/
Download face image as binary buffer
/ memberData?.UserInfo?.faceList?.img => HTTPS image URL from my server
const imageRes = await axios.get(memberData?.UserInfo?.faceList?.img, {
responseType: "arraybuffer"
});
const imageBuffer = Buffer.from(imageRes.data);
/
Create temporary folder for face images (if not exists)
const tmpFolder = path.join(process.cwd(), 'member');
if (!fs.existsSync(tmpFolder)) {
fs.mkdirSync(tmpFolder, { recursive: true });
}
/ memberData.UserInfo.employeeNo => unique identifier used as filename
const imageFilePath = path.join(
tmpFolder,
);
/
Resize image to Hikvision-compatible dimensions (300x400)
/ - Crop from center
/ - Convert to JPEG
/ - Reduce quality for better device compatibility
await sharp(imageBuffer)
.resize(300, 400, {
fit: "cover", / Center crop (similar to Laravel fit)
position: "center"
})
.jpeg({ quality: 85 })
.toFile(imageFilePath);
/
Create multipart/form-data payload for Hikvision API
const form = new FormData();
/ REQUIRED JSON FIELD (must be named exactly "FaceDataRecord")
/ memberData?.UserInfo?.faceList?.FaceDataRecord example:
/ { "faceLibType": "blackFD", "FDID": "1", "FPID": "15277" }
form.append(
"FaceDataRecord",
JSON.stringify(memberData?.UserInfo?.faceList?.FaceDataRecord),
{ contentType: "application/json" }
);
/ Add face image file (field name MUST be "img")
form.append(
"img",
fs.createReadStream(imageFilePath),
{
filename: path.basename(imageFilePath),
contentType: "image/jpeg"
}
);
/
Required request headers for multipart upload
const headers = {
...form.getHeaders(),
'Accept': 'application/json',
'Connection': 'keep-alive'
};
/
Send face data to Hikvision face library
const result = await service.put(
'/ISAPI/Intelligent/FDLib/FDSetUp?format=json',
form,
{ headers }
);
/
Optional: remove temporary image file after upload
/ fs.unlinkSync(imageFilePath);
return { success: true };
} catch (error) {
console.error('
Hikvision face upload failed:', error.response?.data || error.message);
return {
success: false,
error: error.response?.data || error.message
};
}
}
Could you please guide me on how to upload a face image and link it to the correct person on this device?
I have already created a person using the following API:
POST /ISAPI/AccessControl/UserInfo/Record?format=json
I am currently trying to upload a JPG image, but it is not working.
Could you please let me know what I am missing?
async uploadFaceDataBinaryType(memberData, service) {
try {
/
/ memberData?.UserInfo?.faceList?.img => HTTPS image URL from my server
const imageRes = await axios.get(memberData?.UserInfo?.faceList?.img, {
responseType: "arraybuffer"
});
const imageBuffer = Buffer.from(imageRes.data);
/
const tmpFolder = path.join(process.cwd(), 'member');
if (!fs.existsSync(tmpFolder)) {
fs.mkdirSync(tmpFolder, { recursive: true });
}
/ memberData.UserInfo.employeeNo => unique identifier used as filename
const imageFilePath = path.join(
tmpFolder,
face_${memberData.UserInfo.employeeNo}.jpg);
/
/ - Crop from center
/ - Convert to JPEG
/ - Reduce quality for better device compatibility
await sharp(imageBuffer)
.resize(300, 400, {
fit: "cover", / Center crop (similar to Laravel fit)
position: "center"
})
.jpeg({ quality: 85 })
.toFile(imageFilePath);
/
const form = new FormData();
/ REQUIRED JSON FIELD (must be named exactly "FaceDataRecord")
/ memberData?.UserInfo?.faceList?.FaceDataRecord example:
/ { "faceLibType": "blackFD", "FDID": "1", "FPID": "15277" }
form.append(
"FaceDataRecord",
JSON.stringify(memberData?.UserInfo?.faceList?.FaceDataRecord),
{ contentType: "application/json" }
);
/ Add face image file (field name MUST be "img")
form.append(
"img",
fs.createReadStream(imageFilePath),
{
filename: path.basename(imageFilePath),
contentType: "image/jpeg"
}
);
/
const headers = {
...form.getHeaders(),
'Accept': 'application/json',
'Connection': 'keep-alive'
};
/
const result = await service.put(
'/ISAPI/Intelligent/FDLib/FDSetUp?format=json',
form,
{ headers }
);
/
/ fs.unlinkSync(imageFilePath);
return { success: true };
} catch (error) {
console.error('
return {
success: false,
error: error.response?.data || error.message
};
}
}
