Skip to content

Returning media data in actions and functions #1939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cds/cdl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,21 @@ service CatalogService {

Explicitly modelled binding parameters are ignored for OData V2.

#### Returning Media Data Streams { #actions-returning-media}

Actions and functions can also be modelled to return streamed media data like images, CSVs, etc. In order to do so, the action or function's return type has to refer to a [predefined type](#types) annotated with [media data annotations](/guides/providing-services#annotating-media-elements) that is defined in the same service. The minimum set of annotations required is `@Core.MediaType`.

```cds
service CatalogService {
@Core.MediaType: 'image/png' @Core.ContentDisposition.Filename: 'image.png' @Core.ContentDisposition.Type: 'attachment'
type png : LargeBinary;

entity Products as projection on data.Products { ... }
actions {
function image() returns png;
}
}
```

### Custom-Defined Events {#events}

Expand Down