file-uploadodatasapui5

SAPUI5: FileUploader Not Working


I am using sap.ui.unified.FileUploader for uploading file. I am also adding slug and X-CSRF-Token with in header.But i am unable to send header values to gateway, means in gateway side csrf token value is blank.I tested with Rest Client its working fine

code:

View

<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" />

Controller

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);

Solution

  • The attribute "sendXHR" has to be set at the FileUploader instance, not as header parameter. Then it should work.

    oFileUploader.setSendXHR(true);