SAPUI5:FileUploader不工作

时间:2016-03-03 13:03:32

标签: file-upload odata sapui5

我正在使用sap.ui.unified.FileUploader上传文件。我还在slug添加了X-CSRF-Tokenheader。但是我无法向网关发送标头值,网关端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);

1 个答案:

答案 0 :(得分:3)

必须在FileUploader实例中设置属性“sendXHR”,而不是作为标头参数。然后它应该工作。

oFileUploader.setSendXHR(true);