我正在使用sap.ui.unified.FileUploader
上传文件。我还在slug
添加了X-CSRF-Token
和header
。但是我无法向网关发送标头值,网关端csrf token
的值意味着空白。我测试了Rest Client
工作正常
代码:
查看
<u:FileUploader
id="fileUploader1"
name="myFileUpload"
mimeType ="image,text"
uploadUrl=""
uploadOnChange="false"
width="400px"
tooltip="Upload your file to the local server"
uploadComplete="handleUploadComplete" />
<Button
text="Upload File"
press="handleUploadPress" />
控制器
handleUploadPress: function (oEvent) {
var url = "http://xxxxx.xxxx.xxxx:1234/sap/opu/odata/sap/ZGW_GC1_SRV/GCUpload1Set";
var oFileUploader = this.getView().byId("fileUploader1");
oFileUploader.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "slug",
value: oFileUploader.getValue()
}));
oFileUploader.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "x-csrf-token",
value: oController.oModel.getSecurityToken()
}));
oFileUploader.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "sendXHR",
value: true
}));
oFileUploader.setUploadUrl(url);
答案 0 :(得分:3)
必须在FileUploader实例中设置属性“sendXHR”,而不是作为标头参数。然后它应该工作。
oFileUploader.setSendXHR(true);