cancel
Showing results for 
Search instead for 
Did you mean: 

File download no longer working in CAP 8

sven-leonhardt
Explorer
0 Kudos
157

Hi community,

we are in the progress of migrating our CAP7 application to CAP8. In our app we have a function to download an asset from the BTP object store defined like this:

    this.on(download, async (req: Request) => {
      const fileBuffer = await this.objectStoreService.read(
        `assets/${req.data.assetId}`,
      );

      req.http?.res.setHeader('Content-Type', asset.mediaType!);
      req.http?.res.setHeader(
        'Content-Disposition',
        `inline;filename=${asset.fileName}`,
      );
      req.http?.res.send(fileBuffer);
    });

In CAP7 this code worked fine, but now it's giving the following error:

[cds] - Error: Cannot set headers after they are sent to the client

Actually, even the following simple code will now give the error above.

this.on(download, async (req: Request) => {
  req.http?.res.send('OK');
}

Any recommendations on how to implement a file download with CAP8 now?

Thanks

gregorw
Active Contributor
0 Kudos
Have you checked if the CAP Plugins for Attachments and SAP Document Management Service linked at https://cap.cloud.sap/docs/plugins/ work with CAP 8?
sven-leonhardt
Explorer
0 Kudos
HI gregorw, unfortunately the plugins do not fit our requirements (multitenancy, limit of file size, limit of uploads, etc.)
gregorw
Active Contributor
0 Kudos
I'm not suggesting that you should use the plugins. But test them with a small CAP 8 applicaiton and see if there downloads work. And if yes check their coding.

Accepted Solutions (0)

Answers (0)