Skip to content

[Version: 3.13.1] Upload fails for inline attachments with @Core.AcceptableMediaTypes annotation #471

Description

@TiborAdk

Describe the bug

Annotating an inline attachment with @Core.AcceptableMediaTypes leads to the file upload to fail.

(local development using cds watch)

To Reproduce
Steps to reproduce the behavior:

  1. Create an entity with an inline attachment.
using {cuid} from '@sap/cds/common';
using {Attachment, Attachments} from '@cap-js/attachments';

namespace sample

entity Invoices : cuid {
  documentNumber : String;
  // annotation causes file upload to fail
  attachment     : Attachment;
  // Required trigger UI enhancement for attachments due to a different bug.
  attachments    : Composition of many Attachments;
}

annotate Invoices with @(
  UI.LineItem: [ {Value: attachment_filename}],
  UI.Facets  : [] // Required for plugin to add facets
)

(Note: the attachments composition is only required to add the facet for the inline attachment. see: #470)

  1. Expose the entity through a service definition and apply annotation
service AccountinService {
  @odata.draft.enabled
  entity Invoices as projection on my.Invoices;
}
annotate AccounetingServie.Invoices with {
  attachment @Core.AcceptableMediatypes: ['application/pdf']
}
  1. Start development preview with cds watch
  2. Open Fiori preview for AccountingService.Invoices
  3. Create a new entity to open the object page
  4. Select a file to upload for the inline attachment
  5. The upload fails with an on screen error message "The file upload failed".

Logs:

[odata] - PUT /odata/v4/accountin/Invoices(ID=9f9c3291-eccf-40ed-80ac-e9d9c043c3d4,IsActiveEntity=false)/attachment_content 
[cds] - ❗️Uncaught TypeError: Cannot read properties of undefined (reading 'split')
    at checkMimeTypeMatch (.../sample/node_modules/@cap-js/attachments/lib/helper.js:415:33)
    at validateAttachmentMimeType (.../sample/node_modules/@cap-js/attachments/lib/generic-handlers.js:574:8)
    at ApplicationService.putUpdateInlineAttachments (.../sample/node_modules/@cap-js/attachments/lib/plugin.js:601:14)
    at next (.../sample/node_modules/@sap/cds/lib/srv/srv-dispatch.js:57:36)
    at ApplicationService.handle (.../sample/node_modules/@sap/cds/lib/srv/srv-dispatch.js:60:6)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async ApplicationService.draftHandle [as handle] (.../sample/node_modules/@sap/cds/libx/_runtime/fiori/lean-draft.js:1127:7)
[cds] - ❗️server shutdown ...❗️

Expected behavior

When using @Core.AcceptableMediaTypes with an inline attachment, the upload should not fail.

Screenshots

On screen failure message after submiting a document to upload:
Image

Customer Info
Company: TUM project with SAP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions