on 2021 Mar 08 1:23 PM
Hi,
I tried to extend the media sample from https://github.com/SAP-samples/cloud-cap-samples to check out how to display binary data in deep structures.
As example I created an entity Parent having a property "media" as an Composition of Media.
I deleted the media-service.js as to handle the calls automaticly by the default mechanism.
Then I added the Parent entity to the service. For test I added a new Parent object, created an "media" object and PUT the "Test.png" as the binary into it.
Extending the media.http I can view the binary when calling .../Media(1)/content. I also checked it in the Browser and can see, that it is served with Content-Type image/png.
When calling .../Parent(1)/media/content I get the object, but with the Content-Type application/octet-stream.
Has someone a solution how to get the object with the saved Content-Type, when reading it from a deep structure? Is that maybe a bug as it depends GET Request and not the saved object?
data-model.cds:
namespace sap.capire.media;
entity Media {
key id : Integer;
@Core.MediaType : mediaType
content : LargeBinary;
@Core.IsMediaType : true
mediaType : String;
fileName : String;
applicationName : String;
}
entity Parent {
key id : Integer;
media : Composition of Media;
}
media-service.cds:
using { sap.capire.media as db } from '../db/data-model';
namespace sap.capire.media;
service MediaServer {
entity Media as projection on db.Media ;
entity Parent as projection on db.Parent;
}
media.http:
### Requires REST Client for VS Code
### https://marketplace.visualstudio.com/items?itemName=humao.rest-client
###
@protocol = http
@host = localhost
@port = 4004
### Read Pictures
GET {{protocol}}://{{host}}:{{port}}/media-server/Media
Authorization: Basic admin:
### Create Picture with mediatype
POST {{protocol}}://{{host}}:{{port}}/media-server/Parent
Authorization: Basic admin:
Accept: application/json
Content-Type: application/json
{
"id": 1,
"media":{
"id": 1,
"mediaType" : "image/jpeg"
}
}
### Upload Binary PNG
PUT {{protocol}}://{{host}}:{{port}}/media-server/Parent(1)/media/content
Authorization: Basic admin:
Content-Type: image/png
< ./Test.png
### Read Binary
GET {{protocol}}://{{host}}:{{port}}/media-server/Media(1)/content
Authorization: Basic admin:
### Read Binary
GET {{protocol}}://{{host}}:{{port}}/media-server/Parent(1)/media/content
Authorization: Basic admin:
### Delete Image
DELETE {{protocol}}://{{host}}:{{port}}/media-server/Media(1)
Authorization: Basic admin:
best regards
Robert Quindt
Request clarification before answering.
Hi Robert,
The issue is fixed. The fix to be provided with the next release of @sap/cds-runtime. You can follow CAP releases at https://cap.cloud.sap/docs/releases/changelog/.
Best regards,
Vitaly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Robin,
I can reproduce your issue.
We are looking into a fix.
Thanks for reporting!
Johannes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
30 | |
10 | |
8 | |
8 | |
7 | |
7 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.