SAP UI5使用OData上传图像文件

时间:2018-05-14 07:06:38

标签: file-upload upload sapui5

UI5代码为:

<u:FileUploader id="fileUploader" fileType="txt,jpg,png,js" placeholder="Choose a file for Upload..."></u:FileUploader>
<Button text="Upload File" press="fnUplodImage" />

以下是我上传图片的控制器代码

var fileAddress = this.byId("fileUploader");
var file = jQuery.sap.domById(fileAddress.FUEl.id).files[0];
console.log(fileAddress);
var oModelUpload = this.getView().getModel("rulelist2");
oModelUpload.setUseBatch(false);
var oData = {
 Zidentifier1: 'abcd',
 Zidentifier2: '555555',
 Filename: "" + file.name + ""
};
oModelUpload.update("/Ven_FileSet(Zidentifier1='" + oData.Zidentifier1 + "',Zidentifier2='" + oData.Zidentifier2 + "',Filename='" +
 oData.Filename + "')", oData, {
  "method": "PUT",
  success: function(data) {
   console.log("success");
  },
  error: function(e) {
   console.log(e);
  }
 });
  

错误 - 数据服务请求URI标识的资源不允许使用指定的HTTP方法。            任何人都可以在这个流程中找到我错的地方吗?

1 个答案:

答案 0 :(得分:0)

您应该仅为接收上传的文件创建另一项服务,并按照以下方式使用它:

<u:FileUploader uploadUrl="uploadURL/"