Maruthi Revankar
Maruthi Revankar

Reputation: 331

SAPUI5 Upload Collection not uploading File

I am trying to design an interface for user to upload a single file of type excel and limiting size upto 10MB. There are various examples of using the FileUploader control of SAPUI5. But I didn't find any example of using UploadCollection. I am getting the error

Failed to load resource: net::ERR_CACHE_MISS

and the status continues to show Uploading 0%. I am completely new to using these file controls. So please help me out. Here goes my code...

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

Upvotes: 0

Views: 9178

Answers (1)

Thomas
Thomas

Reputation: 21

The parameter "uploadUrl" must point to the backend. Here is my xml.view example:

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

Parameter "NewModel/AttachmentUploadUrl" is filled in corresponding view controller:

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

Upvotes: 2

Related Questions