我尝试使用自定义视觉服务。
回复此错误消息:
{ “代码”: “BadRequestImageFormat”, “消息”: “”}
附上我的代码和测试过的图像文件
请检查并帮助我
<form id="imageform" method="POST" enctype="multipart/form-data">
<input type="file"/>
</form>
var data = new FormData(document.getElementById('imageform'));
var url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/my-key/image";
$.ajax({
url : url,
data : data,
processData : false,
contentType : "multipart/form-data",
headers : {
'Prediction-key' : 'key'
},
type : 'POST',
success : function(response) {
var result = response["Predictions"];
buildResult(result);
},
error : function(request, status, error) {
}
});
我参考了这个文件。
答案 0 :(得分:0)
这对我有用:
function readImage(element) {
var file = element.files[0];
var reader = new FileReader();
reader.onloadend = function() {
$.ajax({
url: "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.1/Prediction/KEY/image?iterationId=ITERATIONID",
data: reader.result,
processData: false,
contentType: "application/octet-streama",
headers: {
'Prediction-key': 'YOUR-KEY'
},
type: 'POST',
success: function(response) {
var result = response["Predictions"];
alert(result);
},
error: function(error) {
alert('error: ' + error);
}
});
}
reader.readAsArrayBuffer(file);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="file" onchange="readImage(this)" />
</form>