Skip to Content

SAP HANA XSJS Classic - Making a multipart POST call to a Machine Learning API - Passing Image


Am tyring to make an external API Call from HANA XS classic by uploading an Image to Public ML API, however the call fails with invalid Key error.

Please see below the code, can you kindly suggest the right way to pass the Key -value pairs for such calls

var ImageDecoded = $.util.codec.decodeBase64(image); // image is read from DB    
request.contentType = "multipart/form-data";
    var entity = request.entities.create();
    request.entities[0].contentType = "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"; // Copied the boundary from Postman generated code
    request.entities[0].headers.set("------WebKitFormBoundary7MA4YWxkTrZu0gW" + 
                "Content-Disposition", "form-data;" +
                "name=\"imageupload\";" +
                ImageDecoded + 
                "Content-Type: image/jpeg" +
    client.request(request, "http://xx.xx.xx.xx:pppp/getImage");
    var response = client.getResponse();  

The response from the server is

BadRequestKeyError: 400 Bad Request: KeyError: 'imageupload'



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers