I want to add an import functionality to a SAPUI5 application. I don't need to upload the file to a server, since I only want to handle the file on the client-side. The FileUploader control that is supplied with SAPUI5 doesn't seem to support that.
One can disable the automatic upload by not setting the uploadOnChange property to true, and then adding a change handler to the control. The change handler has access to the uploaded files via oEvent.getParameters().files,
and can process the uploaded files. When the form that is inside the FileUploader control is never submitted, it won't try to upload the files.
<mvc:View
controllerName="app.controller.Main"
xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:unified="sap.ui.unified"
displayBlock="true">
<Shell id="shell">
<App id="app">
<pages>
<Page id="page" title="{i18n>title}">
<content>
<unified:FileUploader id="ui5-uploader"/>
</content>
</Page>
</pages>
</App>
</Shell>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("app.controller.Main", {
onAfterRendering: function() {
var uploader = this.getView().byId("ui5-uploader");
uploader.attachChange(function(oEvent) {
oEvent.getParameters().files[0].text().then(
function(sContent) {
console.log(sContent);
}
);
});
}
});
});