on 08-21-2020 11:31 AM
Hi,
I'm looking into downloading files using CAP. I'm using a custom handler to download the files (files get fetched from a C4C system using OData). The file download is working except for the fact that the filename is not set and I have to rename the file manually to be able to open it.
Example URL: /ServiceRequestAttachmentFolder('00163E10B4641ED89BF79ACCC3D13BD4')/Binary
This results in following download:
If I rename this file to e.g. test.pdf, I'm able to open the file.
Any ideas on how to set the actual filename? (e.g. attribute on result set, custom header, ...)
Thanks in advance!
Best regards,
Geert-Jan Klaps
UPDATE:
Solved this with following code for now (not the most ideal way since we're manipulating the headers manually, this is something the framework should be able to handle I guess):
req._.odataRes.setHeader('Content-Disposition',`attachment; filename="${result.Name}"`);
OData content disposition annotation was introduced recently
https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.html#contentdispositio...
this annotation needs to be adopted by CDS runtime...
anne.keller FYI..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Oliver, Hi anne.keller,
any news when the runtime will support that annotation?
Best regards
Gregor
Hi 8d8214c7f9734f45be69f95cc0d5aeee,
@Core.ContentDisposition annotation is supported in our last release version cds 5.1.5.
See also https://cap.cloud.sap/docs/guides/providing-services#media-data.
Best regards
Maria
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Maria,
I can not confirm that this is working correctly. My bookshop-demo was already at CDS 5.1.5. My Entity Images in db/schema.cds#L108 is annotated like that:
entity Images : cuid, managed {
@Core.MediaType : mediatype
@Core.ContentDisposition.Filename : filename
content : LargeBinary;
@Core.IsMediaType : true
mediatype : String;
filename : String;
}
when testing this with tests/admin-images.http#L62 I get the header line:
content-disposition: inline; filename="Test.xlsx"
only from the OData V2 Service. When I cange the annotation to
@Core.ContentDisposition: filename
as mentioned in the documentation I get the following error:
And when I test this also the OData V2 Proxy doesnt regurn the content-disposition anymore.
Do I need to file an incident?
Best regards
Gregor
Hi,
Implementing this feature (as proposed by Oliver Klemenz) is now on agenda for node.js runtime.
We will inform you so far the feature is released.
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 Vitaly,
do you have an update when this feature will be shipped? I've updated my sample project bookshop-demo with the annotation @Core.ContentDisposition.Filename:
entity Images : cuid, managed {
@Core.MediaType : mediatype
@Core.ContentDisposition.Filename : filename
content : LargeBinary;
@Core.IsMediaType : true
mediatype : String;
filename : String;
}
in db/schema.cds#L123. But when testing using the REST Client script tests/admin-images.http#L62 I see the header:
content-disposition: inline; filename="Test.xlsx"
Only when doing the call via the V2 proxy.
Best regards
Gregor
Hi Gregor,
when using the CDS OData V2 Adapter Proxy, you can already use the annotation today. For OData V4, Anne can give you additional infos.
Best regards,
Oliver
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
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.