openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

Feature Request: sap.m.upload.Uploader - add error event upon failed uploads

Open jcailan opened this issue 4 years ago • 4 comments

Currently, sap.m.upload.Uploader will always trigger uploadComplete event regardless of the returned status code. Can please provide any means to identify whether the upload was successful or not?

Code from Uploader.prototype.uploadItem:

        oXhr.onreadystatechange = function() {
            var oHandler = that._mRequestHandlers[oItem.getId()];
            if (this.readyState === window.XMLHttpRequest.DONE && !oHandler.aborted) {
                that.fireUploadCompleted({
                    item: oItem
                });
            }
        };

jcailan avatar Dec 14 '21 11:12 jcailan

Hi jcailan, Didn't you get sap.m.upload.Uploader#events/uploadAborted if the upload fails? regards Knut

KnutThies avatar Dec 16 '21 08:12 KnutThies

Hi @KnutThies

No, it didn't trigger. That event only gets triggered when I click on that terminate button in the UI -- see screenshot below:

image

Additionally, I need the response payload to get the error/success information so that I can reflect the status in the UI. Something like below:

image

Just to make this work, I was forced to hack the _mRequestHandlers property to get the xhr instance that made the request. If there was an API provided for that, then the hack can be avoided.

See below workaround logic:

		onUploadCompleted: function(oEvent) {
			var oItem = oEvent.getParameter("item"),
				oUploader = oItem.getParent().getUploader(),
				oXhr = oUploader._mRequestHandlers[oItem.getId()].xhr;

			oItem.setUploadState(UploadState.Complete);

			if (oXhr.status === 200) {
				addStatus(oItem, "uploadCompleted", true);
				setData(oItem, JSON.parse(oXhr.response));
			} else {
				addStatus(oItem, JSON.parse(oXhr.response));
				oItem.setVisibleEdit(false);
			}
		},

Thanks and regards, Jhodel

jcailan avatar Dec 17 '21 08:12 jcailan

Hi @jcailan , Thank you for sharing your enhancement proposal. I've created an internal incident 2180423858. The status of the issue will be updated here in GitHub. Regards, Florian

flovogt avatar Dec 17 '21 12:12 flovogt

Hi @flovogt,

Thanks for bringing this up.

After internal discussions, we understood that this issue should be addressed as development request and hence created backlog item FIORITECHP1-21292 in our internal Jira.

Regards, Keerthi G

KeerthiHere avatar Dec 22 '21 07:12 KeerthiHere

Fixed with 0ae3992a09d3f2b03c1df5ae5730fe5c8d765d97 and available as of 1.98.0.

flovogt avatar Sep 06 '22 06:09 flovogt