从SAP UI5应用程序保存时文件已损坏

时间:2018-10-14 09:04:48

标签: javascript sapui5

我正在尝试将文件保存在UI5应用程序中,但文件损坏。以下是代码

从SAP读取文件

oModelFile.read(itemString, {

success: function (odata, response) {

var fName = odata.ImFilename;

var fType=odata.ImMimeType;

var fMres=atob(odata.ImMediaResource);

if(fType==="text/plain")

{

sap.ui.core.util.File.save(fMres, fName, "txt", fType);

}

if(fType==="image/png")

{

sap.ui.core.util.File.save(fMres, fName, "png", fType);

}

if(fType==="image/jpg")

{

sap.ui.core.util.File.save(fMres, fName, "jpg", fType);

}

if(fType==="application/pdf")

{

sap.ui.core.util.File.save(fMres, fName, "pdf", fType);

}

if(fType==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

{

sap.ui.core.util.File.save(fMres, fName, "xlsx", fType);

}

从上传器读取文件

var reader = new FileReader();

reader.onload = function (e) {

var vContent = e.currentTarget.result.replace("data:" + file.type + ";base64,", "");

that.postImageToBackend(workorderId, that.fileName, that.fileType, vContent);

};

reader.readAsDataURL(file);

在SAP中创建文件

postImageToBackend: function (workorderId, fileName, fileType, Content) {

var itemString = "/ZWOFileSet/";

var serviceURI = "/sap/opu/odata/sap/ZBM_MRKWO_FILE_SRV/";

var oDataModel = new sap.ui.model.odata.v2.ODataModel(serviceURI);

var payload = {

"ImWorkorder": workorderId,

"ImFilename": fileName,

"ImMediaResource": btoa(encodeURI(Content)),

"ImMimeType": fileType

};

oDataModel.create(itemString, payload, {

success: function () {

sap.m.MessageBox.success("Success! ; file Uploaded");

}

},

0 个答案:

没有答案