0

currently i can use url for my classifyImage URL, but i want to use base64string instead. But when i tried that, i got a BadRequestImageFormat error message. what can i do?

app.post('/predict', function(req, res){
const predictionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const endPoint = "https://southcentralus.api.cognitive.microsoft.com"
const projectId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const publishedName = "AntiScam";
const PredictionApiClient = require("azure-cognitiveservices-customvision-prediction");
const predictor = new PredictionApiClient(predictionKey, endPoint);
var data2 = req.body.img;

tempData={ url: data2 };

predictor.classifyImageUrl(projectId, publishedName, tempData)
  .then((resultJSON) => {
       console.log("RESULT ######################")
       console.log(resultJSON);
             res.send(resultJSON);})

  .catch((error) => {
       console.log("ERROR #####################");
       console.log(error);}
);

});

1 Answers1

0

See the API definition here: https://southcentralus.dev.cognitive.microsoft.com/docs/services/Custom_Vision_Prediction_3.0/operations/5c82db60bf6a2b11a8247c15

The only supported requests are either multipart/form-data or by providing an URL to the image. So no, base64 string seems not to be supported.

silent
  • 14,494
  • 4
  • 46
  • 86
  • i have done one on javascript client side where it could convert base 64 to blob and it will work. Any way to convert base64 to blob on node js? – sam tan May 15 '19 at 09:26
  • have you tried to convert your base64 to multipart/form-data? Like here https://stackoverflow.com/questions/4392690/converting-base64-image-to-multipart-form-data-and-sending-with-jquery/6782972 – silent May 15 '19 at 09:29