cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAPUI5 uploadSet: Items not getting refreshed after upload

adarsh-kmr
Explorer
0 Kudos
928

Hi Experts!

I've implemented UploadSet and the files are getting uploaded as expected. But items are not getting refreshed after successful upload. 

 

onUploadCompleted: function (oEvent) {
                var oUploadSet = this.byId("uploadSet");
                oUploadSet.removeAllIncompleteItems();
                oUploadSet.getBinding("items").refresh();
            },
 
There are no errors while debugging.
 

<upload:UploadSet id="uploadSet" instantUpload="false" uploadEnabled="true" afterItemAdded="onAfterItemAdded" uploadCompleted="onUploadCompleted" items="{filteredModel>/items}">

                                    <upload:toolbar />

                                    <upload:items>

                                        <upload:UploadSetItem id="_IDGenUploadSetItem1" fileName="{filteredModel>fileName}" mediaType="{filteredModel>mediaType}" enabledEdit="false" visibleEdit="false" url="{filteredModel>url}" removePressed="onRemovePressed">

                                            <upload:attributes>

                                                <ObjectAttribute id="_IDGenObjectAttribute" title="Uploaded By" text="{filteredModel>createdBy}" active="false" />

                                                <ObjectAttribute id="_IDGenObjectAttribute1" title="Uploaded on" text="{filteredModel>createdAt}" active="false" />

                                                <ObjectAttribute id="_IDGenObjectAttribute2" title="File Size" text="{filteredModel>size}" active="false" />

                                            </upload:attributes>

                                        </upload:UploadSetItem>

                                    </upload:items>

                                </upload:UploadSet>

 

Here I've used JSON model(filteredModel) because the forms entity has 1 to many relationship with the files entity. Hence I'm filtering out the data based on form_id.

 

If I refresh the whole page, I'm getting the expected output.

 

Best regards,

Adarsh

 

 

 

Accepted Solutions (0)

Answers (2)

Answers (2)

Marian_Zeis
Active Contributor

You could try two things, either:

Rebind the model

 

onUploadCompleted: function (oEvent) {
    var oUploadSet = this.byId("uploadSet");
    oUploadSet.removeAllIncompleteItems();
    
    // Rebind the items to the model
    oUploadSet.bindItems({
        path: "filteredModel>/items",
        template: oUploadSet.getBindingInfo("items").template
    });
}

 

Or refresh the model a other way

 

onUploadCompleted: function (oEvent) {
    var oUploadSet = this.byId("uploadSet");
    oUploadSet.removeAllIncompleteItems();
    
    // Refresh the filteredModel directly
    var oModel = this.getView().getModel("filteredModel");
    oModel.refresh(true); // Force update
}

 

shubham_c
Participant

Hello @adarsh-kmr ,
Try this,

onUploadCompleted: function (oEvent) {
this.getView().getModel("filteredModel").setProperty("/items",[]);
var oUploadSet = this.byId("uploadSet");
oUploadSet.removeAllIncompleteItems(true);
oUploadSet.removeAllItems(true);
},

It will clear your upload set attachment which you added locally.

Regards,
Shubham