compreface-sdk
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -46,3 +46,31 @@ /* | ||
}) | ||
} | ||
}, | ||
/** | ||
* Detect faces from given image with blob format | ||
* @param {String} blob | ||
* @param {String} api_key | ||
* @returns {Promise} | ||
*/ | ||
async detect_blob_request(blob, url, api_key){ | ||
var bodyFormData = new FormData(); | ||
bodyFormData.append('file', blob, 'exadel.jpg'); | ||
return new Promise( async (resolve, reject) => { | ||
try { | ||
const response = await axios.post( url, bodyFormData, { | ||
headers: { | ||
...bodyFormData.getHeaders(), | ||
"Content-Length": bodyFormData.getLengthSync(), | ||
"x-api-key": api_key | ||
}, | ||
}) | ||
resolve(response) | ||
} catch (error) { | ||
reject(error) | ||
} | ||
}) | ||
}, | ||
} | ||
@@ -49,0 +77,0 @@ |
@@ -69,2 +69,22 @@ /* | ||
return url; | ||
}, | ||
base64toblob(b64Data, contentType='image/png', sliceSize=512){ | ||
const byteCharacters = atob(b64Data); | ||
const byteArrays = []; | ||
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { | ||
const slice = byteCharacters.slice(offset, offset + sliceSize); | ||
const byteNumbers = new Array(slice.length); | ||
for (let i = 0; i < slice.length; i++) { | ||
byteNumbers[i] = slice.charCodeAt(i); | ||
} | ||
const byteArray = new Uint8Array(byteNumbers); | ||
byteArrays.push(byteArray); | ||
} | ||
const blob = new Blob(byteArrays, {type: contentType}); | ||
return blob; | ||
} | ||
@@ -71,0 +91,0 @@ } |
{ | ||
"name": "compreface-sdk", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "description": "JavaScript SDK for CompreFace - free and open-source face recognition system from Exadel", |
@@ -51,3 +51,4 @@ /* | ||
return new Promise((resolve, reject) => { | ||
detection_endpoints.detect_request(image_path, url, this.key) | ||
image_path = common_functions.base64toblob(image_path); | ||
detection_endpoints.detect_blob_request(image_path, url, this.key) | ||
.then(response => { | ||
@@ -54,0 +55,0 @@ resolve(response.data) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60095
733