0

我正在尝试使用一个文件,在它与 . 我通过 API 文档获得了以下 curl 命令,并且在正确转换时遇到了一些问题。

卷曲命令:

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代码:(我需要添加模型id的表单数据和图片的samplecontent)

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'
        }
    });
});
4

0 回答 0