on 2023 Mar 16 8:12 AM
The data stored through the oData interface is as follows, and the mime type is also automatically given by the standard control FileUploader. However, when the file is obtained through the Get _ Stream, an error HTTP 500 will be reported.
But there is no problem getting PDF files.Then I use hard code to change the mime type to application/msexcel, and then there is no error, but the exported file is garbled, and the content is wrong.In fact,The front-end code is as follows:
var oUrl = this.oDataModel.sServiceUrl + "/MaterialFileStruSet(Matnr='MATERIAL_TEMPLATE_001',ZmatSerial='0001')" + "/$value";
// var oUrl = this.oDataModel.sServiceUrl + "/MaterialFileStruSet(Matnr='AVC_RBT_APPL_UNIT',ZmatSerial='0001')" + "/$value";
var oXHR = new XMLHttpRequest();
oXHR.open('GET', oUrl);
oXHR.responseType = "blob";
oXHR.onload = function() {
if (oXHR.status < 400 && oXHR.response && oXHR.response.size > 0) {
// var sHeaderContentDisposition = decodeURIComponent(oXHR.getResponseHeader("content-disposition"));
// var aHeaderParts = sHeaderContentDisposition.split("filename=");
// aHeaderParts = aHeaderParts[1].split("\"");
// var sFilenameFromServer = aHeaderParts[1];
// var sFilenameFromServer = "test.PDF";
var sFilenameFromServer = "test.xls";
if (sap.ui.Device.browser.msie) {
window.navigator.msSaveOrOpenBlob(oXHR.response, sFilenameFromServer);
} else {
// we have to use an a-element, because we have to set a filename
// other download options do not allow this
var oA = document.createElement("a");
oA.href = window.URL.createObjectURL(oXHR.response);
oA.style.display = "none";
//if (sap.ui.Device.system.phone) {
// for whatver reason, it's not possible to set this for mobile devices
// oA.target = "_blank";
//}
oA.download = sFilenameFromServer;
document.body.appendChild(oA);
oA.click();
document.body.removeChild(oA);
// setTimeout is needed for safari on iOS
setTimeout(function() {
window.URL.revokeObjectURL(oA.href);
}, 250);
}
} else {
sap.m.MessageToast.show("Something went wrong!");
}
}.bind(this);
oXHR.send();
Request clarification before answering.
User | Count |
---|---|
81 | |
29 | |
9 | |
8 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.