question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
GeneralDukecommented, Jan 15, 2016

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…

1reaction
Frank683commented, Jan 15, 2016

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);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to set uploadurl on uploadCollection with ...
Hi All, I am unable to set uploadUrl on uploadCollection object where its instantUpload is false. It called default upload method & upload...
Read more >
UploadCollection instantUpload="false" when Embedded ...
It is not recommended to use UploadCollection directly inside List, Table, etc. but there is a simple workaround. Just put a sap.m.
Read more >
sap.m.UploadCollection - Samples - Demo Kit - SAPUI5 SDK
sap.m.UploadCollection. More. Extends: Control. Application Component: CA-UI5-SC. Available Since: 1.26. Category: Action. Content Density: Compact, Cozy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found