如何在sapui5中将附件从前端发送到后端? 我正在使用上传收集控件。

2020-09-26 13:23发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)用于上传的拖放功能

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


用于上传的拖放功能

3条回答
灬番茄
2020-09-26 14:04

嗨,

使用下面的示例代码。

查看:

 
 
 
 
 
 

在控制器中:

 * ----------------------------------------------  ---------
 * SET CSRF令牌
 * -------------------------------------------------  ------
 var oModel = this.getView()。getModel();
 oModel.mCustomHeaders [" X-CSRF-Token"] ="获取";
 var LeaveTypeSet = {};
 url ="/img/LeaveTypeSet";


 oModel.read(url,null,null,true,function(oData,oResponse){
 that.busyDialog.close();
 oModel.oHeaders [" x-csrf-token"] = oResponse.headers [" x-csrf-token"];
 oModel.bTokenRequested = true;
 LeaveTypeSet = oData;
 var data = {


 " leaveTypeSet":离开类型集


 };
 var jModel = new sap.ui.model.json.JSONModel(data);
 var LeaveTypeId = that.getView()。byId(" leaveformTypeofLeaveId");
 LeaveTypeId.setModel(jModel);
 删除oModel.mCustomHeaders [" X-CSRF-Token"];
 },函数(错误){
 that.busyDialog.close();
//在调用失败的情况下执行
 var obj = JSON.parse(err.response.body);
 var msg = obj.error.message.value;
 var msgTitle =" Error";
 sap.m.MessageBox.show(msg,{
 图标:sap.m.MessageBox.Icon.ERROR,
 标题:msgTitle,
 动作:[sap.m.MessageBox.Action.OK],
 });
 });

 * -------------------------------------------------  ---------
 *其他功能
 * -------------------------------------------------  ---------
 onBeforeUploadFile:function(e){


 var id = e.mParameters.id;
 var fileupload = sap.ui.getCore()。byId(id);


 fileupload.setCustomHeader('slug',e.getParameters()。name);
 fileupload.setXsrfToken(this.getView()。getModel()。oHeaders [" x-csrf-token"]));
 var oFileUpload = that.getView()。byId('fileuploadLV');
 var lbl = oFileUpload._oToolBar.getContent()[2];
 lbl.setText(" PDF附件");
 oFileUpload.setMultipleSelectionEnabled(false);
 that.getView()。byId(" fileuploadLV")。setUploadEnabled(true);
 },


/*处理上载文件事件*/
 onUploadFile:function(oEventData){
 var id = oEventData.mParameters.id;
 var oData = oEventData.getParameters();
 var dataItem = new Object();
//alert("Filename:"+oData.Fieldname)
 var fileupload = sap.ui.getCore()。byId(id);
//检查文件类型和大小
 if(oData.d!=未定义){
 if(oData.d.FileName ==" E_SIZE"){
 fileupload.abortUpload();
 sap.ca.ui.message.showMessageBox({
 类型:sap.ca.ui.message.Type.ERROR,
 消息:"文件大小应小于1 MB"
 });
 返回;
 }否则if(oData.d.FileName ==" E_TYPE"){
 fileupload.abortUpload();
 sap.ca.ui.message.showMessageBox({
 类型:sap.ca.ui.message.Type.ERROR,
 消息:"上传扩展名为.pdf的文件"
 });
 返回;
 }其他{


 dataItem.filename = oData.d.FileName;
//dataItem.documentId = oData.d.Docid;
 if(window.location.href.substring(0,5)!= oData.d .__ metadata.media_src.substring(0,5)){
 oData.d .__ metadata.media_src=
 window.location.href.substring(0,6)+
 oData.d .__ metadata.media_src.substring(5,oData.d .__ metadata.media_src.length);
 }


 dataItem.url = oData.d .__ metadata.media_src;
 dataItem.mimeType = oData.d.ContentType;
 fileupload.commitFileUpload(dataItem);
 }


 }否则if(oData!= undefined){
 if(oData.FileName ==" E_SIZE"){
 fileupload.abortUpload();
 sap.ca.ui.message.showMessageBox({
 类型:sap.ca.ui.message.Type.ERROR,
 消息:"文件大小应小于1 MB"
 });
 返回;


 }否则if(oData.FileName ==" E_TYPE"){
 fileupload.abortUpload();
 sap.ca.ui.message.showMessageBox({
 类型:sap.ca.ui.message.Type.ERROR,
 消息:"上传扩展名为.pdf的文件"
 });
 返回;
 }其他{
 dataItem.filename = oData.FileName;
//dataItem.documentId = oData.Docid;
 dataItem.mimeType = oData.ContentType;
 dataItem.url = oData .__ metadata.media_src;
 fileupload.commitFileUpload(dataItem);


 }
 }
 var oFileUpload = that.getView()。byId('fileuploadLV');
 var lbl = oFileUpload._oToolBar.getContent()[2];
 lbl.setText(" PDF附件");
 that.getView()。byId(" fileuploadLV")。setUploadEnabled(false);
 },




/*处理删除文件事件*/
 onDeleteFile:function(oEventData){
 var id = oEventData.mParameters.id;
 sap.ui.getCore()。byId(id).removeFile(oEventData.mParameters.documentId);
 var model = this.getView()。getModel();
 var fldName ="";
 var sValidate =" AttachmentListSet('')";
 model.remove(sValidate,null,null,false,function(oData,oResponse){
//alert(" success");
 },函数(错误){
 var message = JSON.parse(err.response.body).error.message.value;
 sap.m.MessageBox.show(消息,
 sap.m.MessageBox.Icon.ERROR,
 "错误");
 });
 var oFileUpload = that.getView()。byId('fileuploadLV');
 var lbl = oFileUpload._oToolBar.getContent()[2];
 lbl.setText(" PDF附件");
 that.getView()。byId(" fileuploadLV")。setUploadEnabled(true);


 },
 

一周热门 更多>