Here, I have used simple File Uploader Controller latest version, to demonstrate. I have used the SAP walkthrough code with odata example and in real application situation
<mvc:View controllerName="comZcsvTest.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m" xmlns:u="sap.ui.unified" xmlns:l="sap.ui.layout">
<App>
<pages>
<Page title="{i18n>title}">
<content>
<Text text="hello"/>
<l:VerticalLayout>
<u:FileUploader id="idfileUploader" width="50%" sameFilenameAllowed="false" useMultipart="false" uploadUrl="/sap"
placeholder="Choose a CSV file" style="Emphasized"></u:FileUploader>
<Button text="Upload" press="uploadFile"/>
</l:VerticalLayout>
</content>
</Page>
</pages>
</App>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("comZcsvTest.controller.View1", {
uploadFile: function(oEvent) {
var oFileUploader = this.getView().byId("idfileUploader");
this.csrfToken = this.getView().getModel().getSecurityToken();
oFileUploader.setSendXHR(true);
var headerParma = new sap.ui.unified.FileUploaderParameter();
headerParma.setName('x-csrf-token');
headerParma.setValue(this.csrfToken);
oFileUploader.addHeaderParameter(headerParma);
var headerParma2 = new sap.ui.unified.FileUploaderParameter();
headerParma2.setName('slug');
headerParma2.setValue(oFileUploader.getValue());
oFileUploader.addHeaderParameter(headerParma2);
oFileUploader.checkFileReadable().then(function() {
oFileUploader.upload();
oFileUploader.destroyHeaderParameters();
}, function(error) {
sap.m.MessageToast.show("The file cannot be read. It may have changed.");
}).then(function() {
oFileUploader.clear();
});
},
afterUploadComplete: function(oEvent) {
var response = oEvent.getParameters("response");
this.getView().byId("idfileUploader").clear();
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 |