Skip to Content

How to add Multipart/FormData in JSONModel for loadData call

Aug 14, 2017 at 12:46 PM


avatar image

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("", 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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers