sap.m.UploadCollection拖放问题sapui5 1.52.9

时间:2018-09-07 16:06:12

标签: file-upload sapui5 sap-fiori

自SAPUI5版本1.44.24开始,我们一直在使用控件sap.m.UploadCollection。我们正在使用具有属性InstantUpload =“ false”的控件。在更改事件中,我们使用以下代码将x-csrf-token添加为标头参数,并且可以正常运行:

var oModel = this.getView().getModel();
var oUploadCollection = oEvent.getSource();
oModel.refreshSecurityToken();
var oHeaders = oModel.oHeaders;
var sToken = oHeaders['x-csrf-token'];
// Header Token
var oCustomerHeaderToken = new sap.m.UploadCollectionParameter({
    name: "x-csrf-token",
    value: sToken
    });
oUploadCollection._oFileUploader.setUploadUrl(url);
oUploadCollection.addHeaderParameter(oCustomerHeaderToken);

现在,我们将SAPUI5升级到1.52.9,并且拖放功能似乎已添加到控件中。如果我们不使用拖放功能,则一切正常。现在,如果我们使用拖放功能,则会在change事件上添加header参数。

现在的问题是,我在调用上载方法时收到405(不允许使用方法),由于InstantUpload设置为false,我们手动调用了该方法。

当我调试上载方法时,似乎头参数丢失或FileUploader-dbg.js控制器中不存在头参数,而aRequestHeaders数组中不存在头参数。如果我调试添加的“常规”文件而没有拖放功能,则标头参数设置在aRequestHeaders数组内。在这个问题上有帮助吗?

第一张图片显示了我的问题,参数不存在:Drag and Drop Issue

第二张图片显示了一个可行的方案:Working Scenario

xml视图如下:

<form:content>
<UploadCollection id="UploadCollection" maximumFilenameLength="155" multiple="false" change="onChange" instantUpload="false" fileDeleted="onFileDeleted" filenameLengthExceed="onFileNameExceed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch"
uploadComplete="onUploadComplete" beforeUploadStarts="onBeforeUploadStarts" selectionChange="onSelectionChange"                                 uploadTerminated="onUploadTerminated" noDataText="{i18n>textnoAttachment_Invoice}" mimeType="application/pdf" fileType="pdf, PDF">
</UploadCollection>
</form:content>

基于成功的OData调用的控制器如下所示:

_onCreateSuccess: function(oCheckIn) {

    var oModelControlsUI = this.getView().getModel("controlsUI");
    oModelControlsUI.setProperty("/buttonSubmitEnable", false);
    oModelControlsUI.setProperty("/buttonCancelEnable", false);
    var sId = oCheckIn.WiId;
    var oModel = this.getModel();
    var BindingContext = this.getView().getBindingContext();
    var objectView = BindingContext.getObject();
    objectView.WiId = sId;
    this._sId = sId;

    // Create a new entry in the Model with the newly created entry         
    var oFormInfoContext = oModel.createEntry("/CheckInProcSet", {
        properties: objectView
    });

    //Bind the element to the view not just the form
    this.getView().setBindingContext(oFormInfoContext);
    oModel.refresh();

    //Upload the attachment
    var oCollection = this.getView().byId("UploadCollection");
    oCollection.upload();

}

onBeforeUploadStarts方法如下:

        onBeforeUploadStarts: function(oEvent) {
            // Header Slug
            // Add additional parameter
            //          Get the Model for the form 
            var oModel = this.getModel();
            this.getView().setModel(oModel);
            var BindingContext = this.getView().getBindingContext();
            var objectView = BindingContext.getObject();
            var workitemID = objectView.WiId;
            var doctype = objectView.Ncitype;

            var oCustomerHeaderSlug = new sap.m.UploadCollectionParameter({
                name: "slug",
                value: oEvent.getParameter("fileName") + "|" + workitemID + "|" + doctype
            });

            oEvent.getParameters().addHeaderParameter(oCustomerHeaderSlug);
            // Request the returned entity in JSON format so that we can insert
            // the uploaded file into the upload collection for display
            oEvent.getParameters().addHeaderParameter(new sap.m.UploadCollectionParameter({

                name: "accept",
                value: "application/json"
            }));
},

让我知道是否需要更多信息。

谢谢

1 个答案:

答案 0 :(得分:0)

这是一个已在GitHub(GitHub issue 2199)上报告的问题。答案在GitHub中,但基本上是:

SAP建议我们使用beforefileuploadStart事件代替更改 设置标题参数的事件。可以了一些限制 这种方法也。 oEvent对象没有文件详细信息 例如文件大小,上传时间等。它只有文件名。

谢谢 Jn