I am trying to use a file, after it has been uploaded with the and then create an AJAX request with the file and send it to the einstein vision (predict) api endpoint to get back results of what the photo is. I was given the below curl command through the API documentation and am having a little bit of trouble converting correctly.
curl command:
curl -X POST -H "Authorization: Bearer <Token>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "sampleContent=@generalimage.jpg" -F "modelId=GeneralImageClassifier" https://api.einstein.ai/v2/vision/predict
ajax code: (I need to add form data of model id and samplecontent of the image)
var uploadBtn = $('#upload-button');
uploadBtn.change(function(event) {
event.preventDefault();
var file = event.target.files[0].name;
var formData = new FormData();
formData['sampleContent'] = file;
formData['modelId'] = 'GeneralImageClassifier';
$.ajax({
url: 'https://api.einstein.ai/v2/vision/predict',
method: 'POST',
processData: false,
contentType: false,
data: ???,
headers: {
'Authorization': 'Bearer <Token>',
'Cache-Control': 'no-cache',
'Content-Type': 'multipart/form-data'
}
});
});