Skip to Content

How to determine filename in CAP media entities?

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}"`);
download.png (3.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Aug 22 at 09:14 AM

    OData content disposition annotation was introduced recently
    https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.html#contentdispositiontype

    this annotation needs to be adopted by CDS runtime...

    Anne Keller FYI..

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 24 at 10:18 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.