cancel
Showing results for 
Search instead for 
Did you mean: 

Download attachment from Fiori application using UploadCollection

former_member592880
Participant
0 Kudos

hello,

I'm trying to download an attachment using UploadCollection. I get this error with the code I'm currently trying :

Unable to get property 'getProperty' of undefined or null reference

I have implemented GET_STREAM method in the backend using this blog as a reference :

https://blogs.sap.com/2018/09/18/object-services-attachments-using-uploadcollection/

OData

XML

<UploadCollection id="UploadCollection" noDataText="NO Attachments" uploadEnabled="false">
</UploadCollection>

JS

 var that = this;
   var otxtIONo = that.getView().byId("txtIONo");
   var IONum = otxtIONo.getValue();
   var oUploadCollection = that.getView().byId("UploadCollection");
   var sServiceUrl = "/sap/opu/odata/AAG362/FI_INTERNAL_ORDER_SRV";
   var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
   oModel.setUseBatch(false);
   var Attachment = "/InternalOrderSet('" + IONum + "')/AttachmentSet";
   oModel.read(Attachment, {
    success: function (oData, response) {
     if (oData.results !== "undefined" || oData.results !== null) {
      // oUploadCollection.setModel(oJSONModel, "Attachment");
      var surl = sServiceUrl + "/AttachmentSet(AttachmentGuid ='" + oData.results[0].AttachmentGuid + "')/$value";
      console.log(surl);
      var item = new sap.m.UploadCollectionItem({
       fileName: oData.results[0].Description,
       mimeType: oData.results[0].MimeType,
       url: surl,
       documentId: oData.results[0].InternalOrder,
       // fileSize: oData.results[0].FileSize,
       visibleDelete: false,
       visibleEdit: false
      });
      oUploadCollection.addItem(item);
     }
    },
    error: function (oError) {
     sap.m.MessageBox.show(oError, sap.m.MessageBox.Icon.ERROR, "Error");
    }
   });

please help

thanking you in advance

Siddharth

maheshpalavalli
Active Contributor
0 Kudos

Hi Siddharth Shaligram

Open F12 console and refresh and see from where the error is originating..? put the screenshot here..

Also when the error is coming ? while clicking on the link?

former_member592880
Participant
0 Kudos

while clicking the link:

maheshpalavalli
Active Contributor
0 Kudos

U r testing using mock data?

former_member592880
Participant
0 Kudos

no I'm connected at a dev Server

maheshpalavalli
Active Contributor
0 Kudos

That information is very limited to come to some conclusion 😞

maheshpalavalli
Active Contributor
0 Kudos

And anyreason why you are not using XML view and binding?

former_member592880
Participant
0 Kudos

I coded this using the Fiori SDK for reference, so I created the item and added that to the uploadCollection.

in the item it has a 'url' parameter to unable download that requires a string input. can I submit a hex code of the file to it to download the content.

what is required from the backend to download the files????

maheshpalavalli
Active Contributor
0 Kudos

Hi Siddharth Shaligram, Ohh.. in the backend are you using steam methods to get hte data?

Accepted Solutions (1)

Accepted Solutions (1)

former_member592880
Participant
0 Kudos

hello,

I figured out the download of it, I used a different XML Component (List) to unable download.

xml

 <List id="UploadCollection" items="{attDoc>/docData}" inset="true" showSeparators="None">
          <items>
           <StandardListItem id="UploadCollectionItem" press="docDownload" type="Navigation" iconInset="false"
            title="{parts : [{path : 'attDoc>Description'},{path : 'attDoc>MimeType'}], formatter : 'ui.s2p.mm.purchorder.approve.util.Conversions.formatAttachmentDesc'}"
            icon="{parts : [{path : 'attDoc>MimeType'}], formatter : 'ui.s2p.mm.purchorder.approve.util.Conversions.formatAttachmentIcon'}"
            description="{parts : [{path : 'attDoc>FileSize'}], formatter : 'ui.s2p.mm.purchorder.approve.util.Conversions.formatAttachmentSize'}"></StandardListItem>
          </items>
         </List>

js

//Call this service on press
<SERVICEURL>/AttachmentSet(AttachmentGuid='<AttachmentGuidNo>',FileName='<FileName>')/$value

thanks

Siddharth

Answers (0)