Openui5: Using sap.m.UploadCollection.setUploadUrl() not possible if instantUpload=false

Created on 13 Jan 2016  Â·  18Comments  Â·  Source: SAP/openui5

OpenUI5 version: 1.32.9

Browser/version (+device/version): all

Any other tested browsers/devices(OK/FAIL): not browser related

According to the source code, it is not possible to change the upload URL of an UploadCollection if instantUpload is disabled.

UploadCollection.prototype.setUploadUrl = function(sUploadUrl) {
        if (!this.getInstantUpload()) {
            jQuery.sap.log.info("As property instantUpload is false it is not allowed to change uploadUrl at runtime.");
        }

Please explain the reasons, maybe enhance the documentation of setUploadUrl, or better, make it work.

How would you recommend to solve this?

I have a page with a NavContainer. On several pages within this container information is entered and as last step files can be selected in the UploadCollection. When I finally click "save" a new entity is created on the server by using the create method of v2.ODataModel. Now that I know the entity key which is generated on the server side I set the upload url of the UploadCollection according to the entity path .....sap/opu/odata/ZMYSVC/MyEntity('newKeyValue')/Attachments?$value

Since I can't change the upload Url after the control has been created, I can't make this approach work.

documentation in progress

Most helpful comment

Hello Frank683,
I'm Oli from the SAP dev team which is responsible for the UploadCollection. I got your point and for now I could not confirm that we will adapt the code to enable your use case. I will address your use case to our product team. Nevertheless I want to help you. First some explanation to the use case we build that flag instantUpload for. The use case is close to yours, but the possibility to upload files and attach these files to just created business object is done in a next step of the creation. In other words, the user enter all business object related information and clicks on a “next” button. Now the application creates the business object and the UI changes to the next step (like a wizard). On this step page the UploadCollection is used and instantiated related to the new business object like you do. We also saw the use case that instead of the step page a Popover was used.
And the beginning of the development we got the feedback from the requirement owner that changing the uploadUrl at runtime is not needed. In our team we decided to suppress the possibility. The reason was, to prevent applications to get in trouble. Now I see your use case or a different way to do, so we will rethink about it.
As I saw in the threat you already find a way but of course this could break. I would like to make you a suggestion which is more stable. You can create your own UploadCollection as an extension.
How to extend an existing control: https://openui5.hana.ondemand.com/#docs/guide/d5b756bf4e9a4d67961fa21e1ba12c9e.html
Here you can easily override the setUploadUrl method and make your modification without using internal variables. From a static code point of view, this should work. Feedback is very welcome.

sap.m.UploadCollection.extend("NewUploadCollection", {
metadata: {
},

setUploadUrl : function (value) {
this.setProperty("instantUpload", true, true); // disables the default check
if (sap.m.UploadCollection.prototype.setUploadUrl) {
sap.m.UploadCollection.prototype.setUploadUrl.apply(this, arguments); // ensure that the default setter is called. Doing so ensures that every extension or change will be executed as well.
// Because before we call the original function we override the instantUpload property for short time, to disable the check
}
this.setProperty("instantUpload", false, true); // Afterwords we set back the instantUpload property to be back in a save and consistent state
},

renderer : "sap.m.UploadCollectionRenderer"
});

var oUC = new NewUploadCollection({
instantUpload : false,
uploadUrl : "MyCoolDomain/MyService/$value",
change : function () {
oUC.setUploadUrl("MyCoolerDomain/MyService/MyNewBusinessObject/$value");
}
}).placeAt("MyUploadCollection");

oUC.setUploadUrl("MyCoolerDomain/MyService/MyNewBusinessObject/$value");

var oLabel = new sap.m.Label({
text : oUC.getUploadUrl()
}).placeAt("Label");

Best regards,
Oli..

All 18 comments

Thanks for reporting. I totally get your point and will forward to the dev-team. Internal reference is 1670027733

Since you added the "documentation" label, does it mean you're only gonna mention that it doesn't work in the documentation or are you gonna do something to make it work?

I know, it's private members, and that my code could break with future versions, but since I need it, I just did this and it seems to work.

for (var i = 0; i < oUplCol._aFileUploadersForPendingUpload.length; i++) {
    oUplCol._aFileUploadersForPendingUpload[i].setUploadUrl(sUploadUrl);
}

We have to look into it.
In the end the labels are only a first classification.

Hello Frank683,
I'm Oli from the SAP dev team which is responsible for the UploadCollection. I got your point and for now I could not confirm that we will adapt the code to enable your use case. I will address your use case to our product team. Nevertheless I want to help you. First some explanation to the use case we build that flag instantUpload for. The use case is close to yours, but the possibility to upload files and attach these files to just created business object is done in a next step of the creation. In other words, the user enter all business object related information and clicks on a “next” button. Now the application creates the business object and the UI changes to the next step (like a wizard). On this step page the UploadCollection is used and instantiated related to the new business object like you do. We also saw the use case that instead of the step page a Popover was used.
And the beginning of the development we got the feedback from the requirement owner that changing the uploadUrl at runtime is not needed. In our team we decided to suppress the possibility. The reason was, to prevent applications to get in trouble. Now I see your use case or a different way to do, so we will rethink about it.
As I saw in the threat you already find a way but of course this could break. I would like to make you a suggestion which is more stable. You can create your own UploadCollection as an extension.
How to extend an existing control: https://openui5.hana.ondemand.com/#docs/guide/d5b756bf4e9a4d67961fa21e1ba12c9e.html
Here you can easily override the setUploadUrl method and make your modification without using internal variables. From a static code point of view, this should work. Feedback is very welcome.

sap.m.UploadCollection.extend("NewUploadCollection", {
metadata: {
},

setUploadUrl : function (value) {
this.setProperty("instantUpload", true, true); // disables the default check
if (sap.m.UploadCollection.prototype.setUploadUrl) {
sap.m.UploadCollection.prototype.setUploadUrl.apply(this, arguments); // ensure that the default setter is called. Doing so ensures that every extension or change will be executed as well.
// Because before we call the original function we override the instantUpload property for short time, to disable the check
}
this.setProperty("instantUpload", false, true); // Afterwords we set back the instantUpload property to be back in a save and consistent state
},

renderer : "sap.m.UploadCollectionRenderer"
});

var oUC = new NewUploadCollection({
instantUpload : false,
uploadUrl : "MyCoolDomain/MyService/$value",
change : function () {
oUC.setUploadUrl("MyCoolerDomain/MyService/MyNewBusinessObject/$value");
}
}).placeAt("MyUploadCollection");

oUC.setUploadUrl("MyCoolerDomain/MyService/MyNewBusinessObject/$value");

var oLabel = new sap.m.Label({
text : oUC.getUploadUrl()
}).placeAt("Label");

Best regards,
Oli..

Hi Oli..
I tried like as you suggested, Now am able to set the uploadUrl value in runtime. But the problem is, the am getting Url in runtime for upload, after adding attachment to uploadcollectionitems only .So I can't use the change event of uploadcollection to set the uploadUrl property and I can use with the event of another control only.
Before the another controller event trigger, items are uploaded and pending for upload() execution,because of this setUploadurl is not setting the uploadurl to the already added items which are pending for upload(i.e.,_aFileUploadersForPendingUpload--> uploadUrl:"/../../upoad"). Is there any other way to achieve the same. can u pls suggest?

regards,
Mahi

Hey Mahi,
I see the issue and hopefully got your execution flow. Sorry, but I see no way to archiev what you need without using internal variables. You can override the upload function on your own control and set the uploadUrl on all FileUploader instances inside the _aFileUploadersForPendingUpload array. You should hollow the same approach as before.
Best regards,
Oli..

Hi Oli,
Thanks for the reply, I achieved by overriding the upload function... I expected there will be some other way to reach same solution.
If there is option for setting upload url for _aFileUploadersForPendingUpload array with out overriding, will be nice :)

Hey Mahi,
I adressed the issue to our Product Owner and it is ranked. So we will invest here. Please be aware of that we do no feature downport and in this case I guess we will handle it as a feature.
Best regards, Oli..

Hi Oli,
While working on UploadCollection, I found another issue if instantUpload="false" is set then UploadCollectionItem is not getting listed...
-Mahi

Hey Mahi,
not sure if I got your point correct. In case of instandUpload = false we expect no UploadCollectionItems via Binding and also no UploadCollectioItem template. So both use cases are not supported in on instance. Did I got you?
Best regards,
Oli..

Hi,
My requirement is,
In app for update mode, we are listing the existing request and we are listing existing attachments and also providing option to attach new files not by instandUpload option. Based on submit button action in the app.
In this case,I am trying to use UploadCollection and same time I wanted to list the already attached files against that request.

Problem is, UploadCollectionItem is not getting listed if we set instandUpload = false.

Hey Mahi,
thanks for the details. I talked to our Product Owner and User Interaction Designer. The outcome was, that we will not enhance the UploadCollection in this direction because it could end in a unclear user interaction and system behavior. Sorry for that.
Best regards,
Oli..

Hi Oli,
Thanks for your time to go through my points. If uploadcollection is not going to be enhanced further in this way, what will be the best option for listing & uploading attachments in update mode kind of operations(Note:if instantupload = false). Do we need to use diff. UI for this functionalities.

and one more thing I noticed that, In Firefox(Version:45.0.2) browser attachment is not getting uploaded for the above case which I mentioned earlier. In Chrome browser it is working fine.

Hey Mahi,
You’re welcome :-)
From UX perspective it would be better to have a different UI'S for read / create or update. Nevertheless you can have one UploadCollection to show all existing Attachments with a nice title and one for upload new attachments. If you do so, the user knows where what is :-)

With regards to the second point. We had a regression within the FileUploader control which we are reusing. It should work again with the next patch.
Best regards,
Oli..

Hi,
Can you suggest if getting Url in runtime for upload, after adding attachment to uploadcollectionitems has been fixed.
We have a requirement of adding multiple Attachments, after notes have been created, against the noteGuid created.
For single attachments, we were using File uploader(Working Perfectly).
For Multiple Attachment, we are changing UI5 Control to upload Collection(pending Upload) .
Thanks in Advance

Hello TANYBOSE,

In 1.63 a new control called UploadSet is being introduced and UploadCollection will be deprecated. UploadSet is a completely refactored UploadCollection that contains also long required features such as this one. API is not 100% backwards compatible with the old UploadCollection, hence the new name.

Cheers,
Jan

Hi Jan,

We have recently upgraded to 1.52.17.
I dont think, it will be easy to get upgraded to 1.63.
Can you please suggest a workaround for this issue.

Best Regards;
Tany

Hi Tany,

I've discussed with the team and unfortunately, there is no workaround as the feature was implemented as part of this newly written control. I am really sorry about that.

Regards,
Jan

Was this page helpful?
0 / 5 - 0 ratings