This artifact uses an Object Store as the storage target instead of the underlying database.
Then, the attachment is not stored in the underlying database; instead, it is saved in the respective Object Store, and only a reference to the file is kept in the database, as defined in the CDS model.
To do this, replace the cds-feature-attachments dependency in the pom.xml with:
<dependency>
<groupId>com.sap.cds</groupId>
<artifactId>cds-feature-attachments-oss</artifactId>
<version>${latest-version}</version>
</dependency>A valid Object Store service binding is required for this, typically one provisioned through SAP BTP. See Local development and Deployment to Cloud Foundry on how to use this object store service binding.
For local development, bind to an Object Store service using the cds bind command as described in the CAP documentation for hybrid testing:
cds bind <service-instance-name>This will create an entry in the .cdsrc-private.json file with the service binding configuration. Then start the application with:
cds bind --exec mvn spring-boot:runIf such a binding is not available, use the underlying database as the storage target instead of an Object Store, so use the dependency cds-feature-attachments (not cds-feature-attachments-oss).
The corresponding entry in the mta-file possibly looks like:
_schema-version: '0.1'
ID: consuming-app
version: 1.0.0
description: "App consuming the attachments plugin with an object store"
parameters:
...
modules:
- name: consuming-app-srv
# ------------------------------------------------------------
type: java
path: srv
parameters:
...
properties:
...
build-parameters:
...
requires:
- name: consuming-app-hdi-container
- name: consuming-app-uaa
- name: cf-logging
- name: **object-store-service**
...
resources:
...
- name: **object-store-service**
type: org.cloudfoundry.managed-service
parameters:
service: objectstore
service-plan: standard
The unit tests in this module do not need a binding to the respective object stores, run them with mvn clean install.
The integration tests need a binding to a real object store. Run them with mvn clean install -Pintegration-tests-oss.
To set the binding, provide the following environment variables:
- AWS_S3_BUCKET
- AWS_S3_REGION
- AWS_S3_ACCESS_KEY_ID
- AWS_S3_SECRET_ACCESS_KEY
- AZURE_CONTAINER_URI
- AZURE_SAS_TOKEN
- GS_BUCKET
- GS_PROJECT_ID
- GS_BASE_64_ENCODED_PRIVATE_KEY_DATA
This artifact provides custom handlers for events from the AttachmentService.
- AWS S3
- Azure Blob Storage
- Google Cloud Storage
The plugin supports multi-tenancy scenarios with shared object store instances.
To configure a shared object store instance, set the object store kind to shared:
cds:
attachments:
objectStore:
kind: sharedTo ensure tenant isolation when using a shared object store instance, the plugin prefixes object keys with the tenant ID. When a tenant unsubscribes, all objects prefixed with that tenant's ID are automatically cleaned up from the shared bucket.
Note
Separate object store instances per tenant are not yet supported. This feature is planned for a future release.