Microsoft认知服务:上传图像 [英] Microsoft Cognitive Services: Uploading image

查看:137
本文介绍了Microsoft认知服务:上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从移动设备上传图像到Microsoft Computer Vision API,但我不断收到400错误文件格式请求输入数据不是有效图像。文档说明我可以以下列形式将数据作为application / octet-stream发送:

I am trying to upload an image to the Microsoft Computer Vision API from a mobile device, but I am constantly receiving a 400 Bad Request for Invalid File Format "Input data is not a valid image". The documentation states that I can send the data as application/octet-stream in the following form:


[二进制图像数据]

[Binary image data]

我有base64编码的图像数据(/ 9j / 4AAQSkZJ ..........) ,我也把图像作为FILE_URI,但我似乎无法弄清楚发送数据的格式。以下是示例代码:

I have the data of the image in terms of base64 encoding ("/9j/4AAQSkZJ.........."), and I also have the image as a FILE_URI, but I can't seem to figure out the format in which to send the data. Here is a sample code:

$(function() {
    $.ajax({
        url: "https://api.projectoxford.ai/vision/v1.0/describe",
        beforeSend: function (xhrObj) {
            // Request headers
            xhrObj.setRequestHeader("Content-Type", "application/octet-stream");
            xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", computerVisionKey);
        },
        type: "POST",
        // Request body
        data: base64image,
        processData: false        
    })
    .done(function(data) {
      alert("success");
    })
    .fail(function(error) {
      alert("fail");
    });
});

我尝试了以下内容:


  • [base64image]

  • {base64image}

  • data:image / jpeg; base64,+ base64image

  • image / jpeg; base64,+ base64image

  • [base64image]
  • {base64image}
  • "data:image/jpeg;base64," + base64image
  • "image/jpeg;base64," + base64image

等等。

我在Computer Vision API控制台上测试了这些。是因为base64编码的二进制文件不是可接受的格式吗?或者我是否以完全不正确的格式发送它?

I did tested these on the Computer Vision API console. Is it because base64 encoded binary isn't an acceptable format? Or am I sending it in the incorrect format completely?

注意:当将URL作为application / json发送时,该操作有效。

Note: The operation works when sending a URL as application/json.

推荐答案

请查看 Emotion API项目Oxford base64图像,或直接转到此处的代码段:如何通过.ajax在base64编码中发布图像?

Please take a look at Emotion API Project Oxford base64 image, or go directly to the code snippet here: How to post an image in base64 encoding via .ajax? .

由于这是一个反复出现的话题,我已经提出了一项功能请求,要求API直接处理数据URI, UserVoice

Since this is a recurring topic, I've made a feature request to make the APIs handle data URIs directly, on UserVoice.

这篇关于Microsoft认知服务:上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆