Skip to content

feat: add native server-side copy() for attachment duplication#405

Open
cschuerings wants to merge 2 commits intocap-js:mainfrom
cschuerings:feat/native-copy
Open

feat: add native server-side copy() for attachment duplication#405
cschuerings wants to merge 2 commits intocap-js:mainfrom
cschuerings:feat/native-copy

Conversation

@cschuerings
Copy link
Contributor

Summary

  • Add copy() method to AttachmentsService for server-side attachment duplication across active and draft tables
  • Implement storage-level copy for AWS S3, Azure Blob Storage, and GCP
  • Include safeguards against entity injection, targetKeys override, and copying infected/failed attachments
  • Add demo copyIncident bound action in the incident test FE UI showing the parent-entity copy use case

Closes #279

Details

The new copy() API accepts source and target attachment entities with their keys:

const AttachmentsSrv = await cds.connect.to('attachments')
const newAtt = await AttachmentsSrv.copy(
  sourceAttachments, { ID: sourceId },
  targetAttachments, { up__ID: targetParentId }
)

Supports active-to-active, active-to-draft, and draft-to-draft copies. When targeting a draft table, DraftAdministrativeData_DraftUUID must be provided in targetKeys.

As noted in #279, the primary use case is duplicating attachments when copying a parent entity. The test app demonstrates this with a copyIncident action that creates a new draft incident and clones all its attachments in one operation.

Note on multi-level associations: The copy() API operates on a single attachment composition at a time. For scenarios with nested associations (e.g. Catalog → Books → Attachments, as described in #279), consumers need to iterate over the child entities and call copy() for each.

Introduce a copy() method on AttachmentsService that duplicates an
attachment record and its binary content across active and draft tables.
Includes storage-level implementations for AWS S3, Azure Blob Storage,
and GCP, with safeguards against targetKeys override, entity injection,
and infected/failed source attachments.
Add a bound copyIncident action on ProcessorService.Incidents that
creates a new draft with all attachments cloned via AttachmentsSrv.copy().
The button is shown only in display mode on the Object Page header.
@cschuerings cschuerings requested a review from a team as a code owner March 16, 2026 15:04
@schiwekM
Copy link
Contributor

Hi @cschuerings,
thanks for the contribution - will review till end of week. Maybe we can automatically add the action the the Attachments aspect so the attachments table automatically has the Copy button.

BR,
Marten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable OData Action for Attachment Duplication

2 participants