When using the "CreateImagesFromUrls" endpoint of the Microsoft Cognitive Services Custom Vision Training API I get an error returned for each image saying "ErrorSource".
I am able to create tags using the API so I don't think it's an authentication issue, although it could be that the API can't load the image URL's which are images stored within SharePoint.
I have tried using a few different JSON formats for the HTTP body in the REST call.
This is an SPFX web part built using React and TypeScript. The goal is to load images from a SharePoint library and post them to the Training API. Here's my upload function:
private async uploadImages(tag: string, imageUrls: Array<any>): Promise<String> {
const imageBatch: any = {images:[], tagIds: [tag]};
imageUrls.map(iUrl => {
imageBatch.images.push({url: iUrl, tagIds: [tag], regions: [
{
tagId: tag,
left: 0.0,
top: 0.0,
width: 0.0,
height: 0.0
}
]});
});
console.log('ImageBatch:');
console.log(imageBatch);
//Add images
const keyPostUrl: string = this.endPoint + 'projects/' + this.pRID + '/images/urls';
const requestHeaders: Headers = new Headers();
requestHeaders.append('Content-type', 'application/json');
requestHeaders.append('Cache-Control', 'no-cache');
requestHeaders.append('Training-key', this.trainingKey);
const httpClientOptions: IHttpClientOptions = {
body: JSON.stringify(imageBatch),
headers: requestHeaders
};
return this.context.post(
keyPostUrl,
HttpClient.configurations.v1,
httpClientOptions)
.then((response: Response): Promise<HttpClientResponse> => {
console.log("Sending Images.");
return response.json();
}).then(data => {
console.log(data);
console.log("Is batch successful: " + data.isBatchSuccessful);
});
}
Expected to see isBatchSuccessful = true and the images uploaded. However I get isBatchSuccessful = false, the error of "ErrorSource".
Example of response returned from API:
{
"isBatchSuccessful":false,
"images":[
{
"sourceUrl":"https://myserver.sharepoint.com/sites/dev/Vision%20Training%20List/1234/image_example_752%20-%20Copy%20(2).jpg",
"status":"ErrorSource",
"image":null
},
{
"sourceUrl":"https://myserver.sharepoint.com/sites/dev/Vision%20Training%20List/1234/basic-image-template%20-%20Copy%20(3).png",
"status":"ErrorSource",
"image":null
},
]
}