使用base64进行自定义视觉节点js

时间:2019-05-15 05:37:43

标签: javascript node.js azure microsoft-custom-vision

当前,我可以使用url作为我的classifyImage URL,但是我想改用base64string。但是,当我尝试这样做时,我收到了BadRequestImageFormat错误消息。我该怎么办?

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 个答案:

答案 0 :(得分:0)

在此处查看API定义:https://southcentralus.dev.cognitive.microsoft.com/docs/services/Custom_Vision_Prediction_3.0/operations/5c82db60bf6a2b11a8247c15

仅受支持的请求是multipart/form-data或通过提供图像的URL。所以不,base64字符串似乎不受支持。