In this guide, we use the Tiny-Sample reference sample app as the base application to add the Attachments type to the CDS model.
- You need to prepare the following services for Attachments:
- Entitlement for SAP Object Store with standard service plan for your subaccount
- Entitlement for Malware scanning service with clamav plan for your subaccount
- The following section is where we setup one sample application for development:
mkdir tiny-sample
cd tiny-sample
cds init
cds add tiny-sample
npm i
- To enable attachments, simply adding this self-configuring plugin package into our project:
npm add @cap-js/attachments
- To use Attachments, simply add an element referring to the pre-defined Attachments type as follows:
using {Attachments} from '@cap-js/attachments';
entity Books {
key ID : Integer;
//...
attachments : Composition of many Attachments;
}
cds watch
- While we used SQLite as a low-cost stand-in during development, we're going to use a managed SAP HANA database for production:
cds add hana --for production
- Configure your app for XSUAA-based authentication:
cds add xsuaa --for production
- We'll be using the Cloud MTA Build Tool to execute the deployment on Cloud Foundry:
cds add mta
-
You can refer to the mta.yaml file of this repo for your reference.
-
Run cds build to generate additional deployment artifacts and prepare everything for production in a local ./gen folder as a staging area.
cds build --production
- Now, we use the mbt build tool to assemble everything into a single mta.tar archive:
mbt build -t gen --mtar mta.tar
- Finally, we can deploy the generated archive to Cloud Foundry:
cf deploy gen/mta.tar