SAPUI5上传集合不上传文件

时间:2015-04-14 12:58:42

标签: jquery file-upload sapui5

我正在尝试设计一个界面供用户上传excel类型的单个文件,并将大小限制为10MB。有各种使用SAPUI5的FileUploader控件的示例。但我没有找到任何使用UploadCollection的例子。我收到了错误

  

无法加载资源:net :: ERR_CACHE_MISS

状态继续显示上传0%。我对使用这些文件控件完全不熟悉。所以请帮帮我。这是我的代码......

var upload = new sap.m.UploadCollection({
        busy : false, 
        busyIndicatorDelay : 1000, 
        visible : true, 
        fileType : ["xlsx"], // string[]
        maximumFilenameLength : undefined, // int
        maximumFileSize : 10000000, // int
        mimeType : ["application/x-msexcel", "application/excel"], 
        multiple : false, 
        noDataText : "No Data", 
        sameFilenameAllowed : false, 
        showSeparators : sap.m.ListSeparators.All, 
        uploadEnabled : true, 
        uploadUrl : "D:\Downloads", 
        tooltip : undefined,    
        parameters : [], 
        change : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ],
        fileDeleted : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ],
        filenameLengthExceed : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ],
        fileRenamed : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ],
        fileSizeExceed : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ],
        typeMissmatch : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ],
        uploadComplete : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ],
        uploadTerminated : [ function(oEvent) {
            var control = oEvent.getSource();
        }, this ]
    });

1 个答案:

答案 0 :(得分:2)

参数“uploadUrl”必须指向后端。这是我的xml.view示例:

                    <UploadCollection id="UploadCollection" xmlns="sap.m"
                        busy="false" busyIndicatorDelay="1000" maximumFilenameLength="55"
                        multiple="false" 
                        items="{Attachments}" 
                        showSeparators="None"
                        fileDeleted="onFileDeleted" 
                        fileRenamed="onFileRenamed"
                        uploadEnabled="true" 
                        uploadUrl="{NewModel>/AttachmentUploadUrl}"
                        uploadComplete="onUploadComplete"
                        UploadTerminated="onUploadTerminated"
                        change="onChange"> 
                        <UploadCollectionItem contributor="{CreatedByUserName}"
                            documentId="{AttachmentGuid}" 
                            fileName="{FileName}" 
                            mimeType="{MimeType}"
                            uploadedDate="{CreationUtcDateTime}"
                            url="{ path: 'url', formatter: 'ztl_mm_inv_apr.util.formatter.media_src' }"
                            enableEdit="false" enableDelete="false" />
                        <headerParameters>
                            <UploadCollectionParameter name="x-csrf-token"
                                value="{NewModel>/csfrToken}" />
                        </headerParameters>
                    </UploadCollection>

参数“NewModel / AttachmentUploadUrl”填写在相应的视图控制器中:

            // Path Upload Attachment
            // Example http://xyz.../sap/opu/odata/sap/ZUI5_MM_INV_APR_SRV/WorkitemSet(000000108068)/Attachments
            itemModel.AttachmentUploadUrl = window.location.origin + (oContext.getModel().sServiceUrl + sItemPath ) + "/Attachments" ;