I am using the npm package clarifai
to access the Clarifai API. I need to use the getTagsByImageBytes
function, but I get this answer:
{"status_code":"ALL_ERROR","status_msg":"All images in request have failed. Please review the error messages per image.","meta":{},"results":[{"docid":2.0371991595148082e+38,"status_code":"CLIENT_ERROR","status_msg":"Data loading failed, see results for details. ","local_id":"","result":{"error":"data 0 is not a valid because: Data is corrupt or data type is not supported.."},"docid_str":"99430754f1cd37d149b992bc635f685f"}]}
I have a problem with my image encoding. Here is how I attempted to get it so far (path
is the local path to my image and bytes
the variable I want to send to Clarifai):
const fs = require('fs');
let path = 'path/to/any/image';
let buffers = [];
let bytes;
// creating a reading stream
const readable = fs.createReadStream(path);
// the read content is added to the buffer array
readable.on('data', (chunk) => {
buffers.push(chunk);
});
// all the data read are joined in a single buffer
readable.on('end', () => {
bytes = Buffer.from(buffers.join(), 'binary').toString('base64');
// here the goal is to have a valid base64 encoded image
console.log(bytes);
});
I have also unsuccessfully tried to send the JSON.stringify
and the .toString
version. I think I miss something in my nderstanding of the expected bytes array, is there anyone to help me?
thanks!
UPDATE: I changed the code and the error message above to update my last attempts.