cancel
Showing results for 
Search instead for 
Did you mean: 

FileUploader SAPUI5 Version 1.103

axitycesarfelce
Participant

Hi all,

The past week SAP upgraded the Fiori Launchpad Sites in Neo with Maintenance version 1.103. Now my apps are failing specifically with FileUploader Component.

The Script is easy

var fU = this.getView().byId("idfileUploader");
var domRef = fU.getFocusDomRef();

The response of domRef is version 1.103 is <Button.....

The response of domRef version 1.102 is <Input.....

We need the input, how does it work in the new version, since the demokit is still in 1.102.

var file = domRef.files[0]; //Input
var reader = new FileReader(); reader.onload = function (evt) {...} reader.readAsBinaryString(file);


regards,
César

boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

> we copied the code from some blog

Could you please share the blog post from which you copied the code?

IMHO: technical blog posts (especially written by non-SAP employees) should be avoided or regarded as a hint at best (including Stack Overflow answers) but not as something from which you can just copy their code to the production code. To make it worse, technical blog posts are rarely maintained and abandoned after they're published.

I personally find it is frustrating that such blog posts are very much discoverable compared to official documentation..

gregorw
Active Contributor
axitycesarfelce
Participant
0 Kudos

boghyon.hoffmann, This was developed along time ago, more than 5 years, but we find it in the community in this message https://answers.sap.com/questions/12347717/read-file-using-fileuploader.html, that has a link to https://saplearners.com/how-to-upload-csv-file-data-in-sapui5sap-fiori-applications/, in step 5, is the same code that we have.

regards,

axitycesarfelce
Participant
0 Kudos

boghyon.hoffmann, thanks to gregor.wolf there is another blog that uses the same code as mine,

https://blogs.sap.com/2021/07/26/file-upload-and-download-in-sap-ui5/

If this method is protected, why in every blog, they use it?

regards,

boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

> If this method is protected, why in every blog, they use it?

That's the tragedy.

As much as SAPUI5 framework developers take the compatibility very seriously for existing applications, application developers have to take the API visibility in the API reference also very seriously in order to avoid being affected by the framework code changes.

Please don't rely on protected/private methods from the framework in the application code (typically some controller).

boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

Please do not encourage future readers to access undocumented private properties and protected APIs!

Not following those guidelines will break the application in the future.

Instead, refer to API reference and samples of "sap.ui.unified.FileUploader". If the documentation is lacking in samples, create an issue in https://github.com/SAP/openui5/issues/new

Accepted Solutions (0)

Answers (2)

Answers (2)

Hello binpath82.

I was facing the same issue in my application.

I have resolved it by adding the change event instead reading from domRef() at upload button press.

XML View:

<u:FileUploader id="fileUploader" change="onFileChange"/>

JS Controller:

onFileChange: function(oEvent){

var file = oEvent.getParameters("files").files[0];

}

Regards,

Jaffar.

axitycesarfelce
Participant
0 Kudos

Hello jaffarsadik,

Awesome! it's not a bad idea! Let me test it!

regards,

boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

The visibility of the API "getFocusDomRef" is protected, i.e. it's not allowed to be called directly in application code. That API is rather intended to be overwritten in control development if needed.

But why do you need to access the internal input element? FileUploader samples for 1.103.0 are here: https://ui5.sap.com/1.103.0/#/entity/sap.ui.unified.FileUploader

axitycesarfelce
Participant
0 Kudos

Hi boghyon.hoffmann, thanks for your response!

I need to get the input because later we readed on the fly with "var reader = new FileReader()"

we need to process each line to validate what is loaded, we copied the code from some blog.

regards,

Cesar