Using sap.m.UploadCollection.setUploadUrl() not possible if instantUpload=false
See original GitHub issueOpenUI5 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:
- Created 8 years ago
- Comments:18 (8 by maintainers)
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…
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.