
method DEFINE.
super->define( ).
Data: lo_entity TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_property TYPE REF TO /iwbep/if_mgw_odata_property.
lo_entity = model->get_entity_type( iv_entity_name = 'ZFILE' ).
IF lo_entity IS BOUND.
lo_property = lo_entity->get_property( iv_property_name = 'Filename').
lo_property->set_as_content_type( ).
ENDIF.
endmethod.
method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
data: lw_file type zfile.
field-symbols:<fs_key> type /iwbep/s_mgw_name_value_pair.
read table it_key_tab assigning <fs_key> index 1.
lw_file-filename = iv_slug.
lw_file-value = is_media_resource-value.
lw_file-mimetype = is_media_resource-mime_type.
lw_file-sydate = sy-datum.
lw_file-sytime = sy-uzeit.
insert into zfile values lw_file.
endmethod.
method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM.
data : ls_stream type ty_s_media_resource,
ls_upld type zfile.
lv_filename type char30.
field-symbols:<fs_key> type /iwbep/s_mgw_name_value_pair.
read table it_key_tab assigning <fs_key> index 2.
lv_filename = <fs_key>-value.
select single * from zfile into ls_upld where filename = lv_filename.
if ls_upld is not initial.
ls_stream-value = ls_upld-value.
ls_stream-mime_type = ls_upld-mimetype.
copy_data_to_ref( exporting is_data = ls_stream changing cr_data = er_stream ).
endif.
endmethod.
method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~UPDATE_STREAM.
data: lw_file type zfile.
field-symbols:<fs_key> type /iwbep/s_mgw_name_value_pair.
read table it_key_tab assigning <fs_key> index 1.
lw_file-filename = <fs_key>-value.
lw_file-value = is_media_resource-value.
lw_file-mimetype = is_media_resource-mime_type.
lw_file-sydate = sy-datum.
lw_file-sytime = sy-uzeit.
modify zfile from lw_file.
endmethod.
METHOD fileset_get_entityset.
DATA:
it_final TYPE STANDARD TABLE OF zfile,
lt_filters TYPE /iwbep/t_mgw_select_option,
ls_filter TYPE /iwbep/s_mgw_select_option,
ls_so TYPE /iwbep/s_cod_select_option,
p_name TYPE c LENGTH 15.
SELECT
mandt
filename
SYDATE
SYTIME
VALUE
MIMETYPE
FROM zfile
INTO TABLE et_entityset.
ENDMETHOD.
<mvc:View xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:u="sap.ui.unified" controllerName="File_Upload.controller.View1" displayBlock="true">
<App>
<pages>
<Page title="Upload The File">
<content>
<Label text="Put your Documents here" width="100%" id="__label0"/>
<u:FileUploader id="fileUploader" useMultipart="false" name="myFileUpload" uploadUrl="/destinations/TRN/sap/opu/odata/sap/ZFILE_SRV/FILESet" width="400px" tooltip="Upload your file to the local server" uploadComplete="handleUploadComplete"/>
<Button text="Upload File" press="handleUploadPress"/>
<List id="itemlist" headerText="Files" class="sapUiResponsiveMargin" width="auto" items="{ path : 'Data>/FILESet' }">
<items>
<ObjectListItem id="listItem" title="{Data>Filename}">
<ObjectAttribute text="Download" active="true" press="fun"/>
</ObjectListItem>
</items>
</List>
</content>
</Page>
</pages>
</App>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator",
"sap/ui/model/odata/ODataModel",
"sap/m/MessageToast",
"sap/m/Button",
"sap/m/Dialog",
"sap/m/MessageBox",
"sap/m/List",
"sap/m/StandardListItem"
], function(Controller, Filter, FilterOperator, ODataModel, MessageToast, Button, Dialog, MessageBox, List, StandardListItem) {
"use strict";
var name;
var mandt;
var oModel = new sap.ui.model.odata.ODataModel("Put path of Odata with destination Here");
return Controller.extend("File_Upload.controller.View1", {
handleUploadComplete: function() {
sap.m.MessageToast.show("File Uploaded");
var oFilerefresh = this.getView().byId("itemlist");
oFilerefresh.getModel("Data").refresh(true);
sap.m.MessageToast.show("File refreshed");
},
handleUploadPress: function() {
var oFileUploader = this.getView().byId("fileUploader");
if (oFileUploader.getValue() === "") {
MessageToast.show("Please Choose any File");
}
oFileUploader.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "SLUG",
value: oFileUploader.getValue()
}));
oFileUploader.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "po",
value: "12234"
}));
oFileUploader.addHeaderParameter(new sap.ui.unified.FileUploaderParameter({
name: "x-csrf-token",
value: oModel.getSecurityToken()
}));
oFileUploader.setSendXHR(true);
oFileUploader.upload();
},
fun: function(oEvent) {
var ctx = oEvent.getSource().getBindingContext("Data");
name = ctx.getObject().Filename;
mandt = ctx.getObject().Mandt;
var oModel = new sap.ui.model.odata.ODataModel("Put path of Odata with destination Here");
oModel.getData("/Data");
oModel.read("/FILESet(Mandt='" + mandt + "',Filename='" + name + "')/$value", {
success: function(oData, response) {
var file = response.requestUri;
window.open(file);
},
error: function() {
}
});
},
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |