无法使用SAP UI5 FileUploader上载多个文件

时间:2016-02-02 05:55:50

标签: javascript sapui5

我使用以下代码将多个文档上传到服务器。

 var docFileUploader = new sap.ui.unified.FileUploader({
    name : fileUploaderName,
    uploadOnChange: false,
    uploadUrl: uploadUrlStr,
    ***multiple:true,***
    additionaldata : nodeObjId ,
    fileSizeExceed: function (oEvent) {
        var sName = oEvent.getParameter("fileName");
        var fSize = oEvent.getParameter("fileSize");
        var fLimit = oFileUploader.getMaximumFileSize();
        Messenger().post({
            message: "File: " + sName + " is of size " + fSize + " MB which exceeds the file size limit of " + fLimit + " MB.",
            type: 'error',
            showCloseButton: true
        });
    },
    uploadComplete: function (oEvent) {                                                             
        var sResponse = oEvent.getParameter("response");
        console.log(sResponse);
        var thisDlg = this.getParent().getParent().getParent().getParent();
        console.log(thisDlg);

        if (sResponse) {
            var m = /^\[(\d\d\d)\]:(.*)$/.exec(sResponse);
            if (m[1] == "200") {
                uploadSuccess = true;
                thisDlg.setBusy(false);
                console.log("The document has been uploaded successfully");
                            setTimeout(function() { Messenger().post("The document has been uploaded successfully");}, 100);
            } 
            else {
                thisDlg.setBusy(false);
                setTimeout(function() { Messenger().post({
                     message: 'Oops! Error in document upload. <br>Please try again or contact your administrator.',
                     type: 'error',
                     showCloseButton: true
                });},100);
            }
        }

        thisDlg.setBusy(false);
        console.log("The document has been uploaded successfully");
        setTimeout(function() { Messenger().post("The document has been uploaded successfully");}, 100);

        thisDlg.close();    
        thisDlg.destroy();

        setTimeout(function() { reloadPage(attrGrpName); }, 100);
    }
});

控制器部分如下:

@RequestMapping(value = "doc/upload", method = RequestMethod.POST, consumes = "multipart/form-data")
public @ResponseBody String uploadDoc(@RequestParam("uploadDoc-data") ObjectId nodeId,
        @RequestParam(value = "uploadDoc", required = true) MultipartFile[] files, @RequestParam String userId, @RequestParam String passwd) {
    if (files != null) {
        return service.uploadDoc(nodeId, files[0], userId, passwd);
    } else
        return "No files found to upload";
}

即使我使用文件[0]也给我一个 ArrayIndexOutofBound 0异常。这意味着MultipartFile []仅返回一个空数组。我能够上传一个没有multiple属性的文件。如果我将multiple属性设置为&#39; true&#39;则会出现问题。我错过了什么?请帮帮我。

0 个答案:

没有答案