on 12-30-2020 1:06 AM
Hello everybody,
I have an issue when I want to to upload files and send to my Odata.
The slug parameter is always empty but when I use the gateway client and add in the header it works correctly.
I thcked my entity as media and modified the MPC_EXT
Here my code, I hope you would help me.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/Item",
"sap/ui/model/json/JSONModel",
"sap/m/upload/Uploader",
"sap/m/ObjectMarker",
"sap/m/MessageToast",
"sap/m/UploadCollectionParameter",
"sap/ui/core/format/FileSizeFormat",
"sap/m/library",
"sap/ui/core/Fragment",
"sap/m/Image"
], function (Controller, MessageToast) {
"use strict";
var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZHR_XXXXXX_SRV");
return Controller.extend("generated.app.controller.Main", {
handleUploadComplete: function (oEvent) {
sap.m.MessageToast.show("File Uploaded");
var sResponse = oEvent.getParameter("response");
if (sResponse) {
var sMsg = "";
var m = /^\[(\d\d\d)\]:(.*)$/.exec(sResponse);
if (m[1] === "200") {
sMsg = "Return Code: " + m[1] + "\n" + m[2] + "(Upload Success)";
oEvent.getSource().setValue("");
} else {
sMsg = "Return Code: " + m[1] + "\n" + m[2] + "(Upload Error)";
}
MessageToast.show(sMsg);
}
},
postFileToBackEnd: function( Pernr, FileConn, FileConnType, Content) {
debugger;
var payLoad = {
"ImPernr": "00000123",
"ImFilenameConn": FileConn,
"ImMimeTypeConn": FileConnType,
"ImMediaRessConn": btoa(Content)
}
this.getOwnerComponent().getModel().create("/FileSet()", payLoad, {
success: function (odata, Response) {
if (odata !== "" || odata !== undefined) {
sap.m.MessageToast.show("Created successfully");
} else {
sap.m.MessageToast.show("New entry not created");
}
},
error: function (cc, vv) {
}
});
},
handleUploadPress: function (oEvent) {
var oFileConn = this.getView().byId("Fileconn");
var oFileBill = this.byId("Filebill");
var oFile1 = this.byId("Fileconn").getValue();
var domRef1 = oFileConn.getFocusDomRef();
var oFile2 = this.byId("Filebill").getValue();
var domRef2 = oFileBill.getFocusDomRef();
var oCheck = this.byId("checkbox").getSelected();
if ((oFile1 == "") && (oFile2 == "") && (oCheck == "")) {
var Msgv0 = this.getView().getModel("i18n").getResourceBundle().getText("novalue");
sap.m.MessageToast.show(Msgv0);
return;
} else {
oFileConn.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "SLUG",
value: oFileConn.getValue()
}));
oFileConn.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "po",
value: "12234"
}));
oFileConn.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "x-csrf-token",
value: oModel.getSecurityToken()
}));
oFileConn.setSendXHR(true);
oFileConn.upload();
var file1 = domRef1.files[0];
var that = this;
this.fileConn = file1.name;
this.fileconnType = file1.type;
var file2 = domRef2.files[0];
this.fileBill = file2.name;
this.fileBType = file2.type;
var reader = new FileReader();
reader.onload = function (e) {
var vContent = e.currentTarget.result.replace("data:" + file1.type + ";base64,", "");
//var vContent2 = e.currentTarget.result.replace("data:" + file2.type + ";base64,", "");
that.postFileToBackEnd("00000123", that.fileConn, that.fileconnType, vContent);
};
reader.readAsDataURL(file1);
}
}
});
});
Thank you in advance for your help.
Mohamed.
User | Count |
---|---|
84 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.