cancel
Showing results for 
Search instead for 
Did you mean: 

MDK Offline File Handling --> SAP Gateway

tschnur_nagarro
Explorer

Hello,

we have the following OData Entities modelled and implemented in SAP Gateway:

As you can see we have a "Product" Entity and 1..n attachments (MediaFile Entity) for each Product. The media entity is annotated with (hasStream ="true") and as you can see there is no dedicated property in the MediaFile Entity to pass the binary content to a caller. This is usually handled in SAP Gateway by adding a "/$value" to the end of the URL to tell the Gateway that the actual file content is requested instead of just the file metadata.

In my MDK app I want to use an attachment control to display the attachments for a product. Therefore I created an OData offline action to fetch the metadata for a file that is called when a product page is opened:

{
    "Service": "/TEST/Services/TestService.service",
    "DefiningRequests": [
    {
        "Name": "Product{Nodekey}",
        "Query": "{@odata.readLink}/ToMediaNav",
        "AutomaticallyRetrievesStreams": true
    }
],
    "_Type": "Action.Type.OfflineOData.Download",
    "ActionResult": {
        "_Name": "sync"
    },
    "OnFailure": "/TEST/Actions/Service/SyncFailureMessage.action",
    "OnSuccess": "/TEST/Rules/InitializeAttachments.js" 
}

As you can see I used the AutomaticallyRetrieveStreams property to tell the App that I also want to fetch the actual file content. However while this correctly reads the file metadata (filename, mime type, size etc.) from the back-end the $value request as mentioned earlier is never called. I can't see any further back-end calls by the framework at all when checking the logs. Since the documentation of AutomaticallyRetrieveStreams seems non existent can someone tell me what this acutally does? How should the odata back-end entity look like? Should it have a dedicated property of type Edm.Binary for the file content? Why does any "isMediaLocal" call in my MDK app returns "false"?

Thanks in advance

Tobias

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

tschnur.nagarro

Were you able to resolve your issue? If any of the below responses helped you, then please mark the helpful answer by accepting it OR post an answer so others might benefit from your findings and then close this discussion.

Regards,
Jitendra (SAP Community Moderator)

Accepted Solutions (0)

Answers (2)

Answers (2)

tschnur_nagarro
Explorer

Thanks for you reply Bill. Basically your first sentance is my problem. From a logical perspective it looks clear to me what AutomaticallyRetrieveStreams and isMediaLocal should do. I would expect that the file content is automatically retrieved from the back-end and stored in the offline odata storage. As a result the isMediaLocal should return true as soon as this is finished.

However it looks like nothing is happening. Since my ODataOffline Action only triggers one back-end request to fetch the file metadata for a certain product what works great (I have chosen your approach 2. for obious performance reasons). However I can't see any further back-end requests fetching the file content. What kind of request should I expect here from a technical perspective. Is the MDK actually triggering a $value request?

I honestly have to say that the MDK Documentation is horrible when it comes to File Handling. There is one small example without any explanation what happens in the background and how the odata calls technically look like.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Can you share your download action that you are calling to retrieve the selected item on demand?

miqueias_maia
Participant
0 Kudos

Hello tschnur.nagarro.

I definetly agree with your comment about the documentation. We have to try and try again until to find a solution. I'm with this issue right now.

My action saves the image on db and I can retrieve the data as ID and another image properties, but I can't display the image if it is not offline.

Did u solved your issue? Could u explain how do u solve it?

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Automatically Retrieve Streams will download the actual media associated with the Entity and store it in the offline db. The isMediaLocal can be used to query the offline db to determine if the media resource has already been downloaded to the offline db.

In terms of the properties of your media entity, for a media entity (hasStream=true) those should not have a dedicated property for the actual media resource.

For your offline initialization action, when dealing with media entities I would normally just include that entity in my defining requests. The decision to then make is if you want to either

  1. Pre-download all the media resources into the offline db which will require additional time during initialization by setting automatically retrieve streams ...or...
  2. Download "on demand" when the user wants to view / use the actual media resource

In the first case you then just need to call Download Media to retrieve the media from the offline db for use. For the second, you will need to have a Download action add a defining request to download the requested media resource to retrieve it from the backend to the offline db before then calling Download Media to consume it in the application.

In either case since the entity was in the initialization defining requests the other properties are always available and accessed just like any other entity.

I would recommend creating the navigation from your Media File back to the Product entity.