Skip to Content
avatar image
Former Member

How to add Multipart/FormData in JSONModel for loadData call

I want to make a POST call with JSONModel().loadData() method which takes formadata as payload/requestData. Its not working for me, I am getting 400 bad request. When I try the same thing with xhr it works fine.

Here is the code snippet which i have been trying,

var sHeaders = {"content-type":"multipart/form-data; boundary=---011000010111000001101001","Accept":"application/json","APIKey":"ok472SzihtnzB8m0VYZBsLcQGdzx8GY"};

var oModel = new sap.ui.model.json.JSONModel();

var oData = new FormData();

oData.append("options", "{\"numTopics\":2, \"numTopicsPerDoc\":1,\"numKeywordsPerTopic\":15}");

oData.append("files", new Blob(["tests"],{type: "text/plain"}), "text1.txt"); oData.append("files", new Blob(["tests"],{type: "text/plain"}), "text2.txt"); oModel.loadData("https://sandbox.api.sap.com/ml/topicdetection/inference_sync", null, true, "POST", oData, false, sHeaders);

oModel.attachRequestCompleted( function(oEvent){

var oData = oEvent.getSource().oData;

});

Is there a specific way to add formdata in jsonModel which i am doing wrong.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers