SAP Knowledge Base Article - Public

2884225 - Failed to Load PDF Document When Using API_CV_ATTACHMENT_SRV AttachmentContentSet

Symptom

When uploading attachments using the API `API_CV_ATTACHMENT_SRV` with the method `AttachmentContentSet`, the following issues occur:

  • Attachments are not viewable in SAP Fiori UI
  • Error message "Failed to load PDF document" appears when attempting to view an attachment
  • Upload appears successful, but when downloaded the files get corrupted and is inaccessible for the user

Environment

  • SAP S/4HANA Cloud
  • Document Management Service (DMS)
  • API_CV_ATTACHMENT_SRV (OData Attachment Service)

Cause

The attachment upload fails to display due to incorrect file encoding:

  1. The file (e.g., PDF) has been encoded (typically BASE64) before being passed to the API.
  2. While the Attachment Service API accepts and stores the encoded content in the repository, the SAP Fiori UI cannot decode the file back to its original format.
  3. The UI expects raw binary data, not encoded content.
  4. This results in successful upload but failed retrieval/viewing.

Root Cause: The API `API_CV_ATTACHMENT_SRV/AttachmentContentSet` requires files to be uploaded as raw binary data without any encoding layer.

Resolution

Upload attachments as raw files without encoding (e.g., without BASE64 encoding):

  1. Pass the file as raw binary data to the `AttachmentContentSet` method
  2. Set the correct MIME type in the request headers:
    1. For PDF files: use `application/pdf`
    2. For other file types: use the appropriate MIME type

Implementation Examples

 

Using POSTMAN/BRUNO:

  • Select Body → Binary
  • Choose the file directly
  • Set headers:
    • `Content-Type: application/pdf` (for PDF files)
    • `slug: filename.pdf`

 

In Custom Development:

```

// Pseudo-code example

// Read file as raw binary (NOT BASE64 encoded)

binaryContent = readFileAsBinary(filePath)

// Set request headers

headers = {

    'Content-Type': 'application/pdf',

    'slug': 'document.pdf'

}

// POST to API

POST /API_CV_ATTACHMENT_SRV/AttachmentContentSet

Body: binaryContent (raw)

```

Common MIME Types:

File Type

MIME Type

PDF

application/pdf

JPEG

image/jpeg

PNG

image/png

Word Document

application/vnd.openxmlformats-officedocument.wordprocessingml.document

Excel

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Text

text/plain

Keywords

POST , slug , API_CV_ATTACHMENT_SRV, AttachmentContentSet, BASE64, PDF upload, Failed to load PDF document, attachment service, raw file, binary upload, MIME type, Document Management Service, DMS, S/4HANA Cloud , KBA , CA-DMS , Document management , PLM-FIO-DMS , Fiori UI for Document management , Problem

Product

SAP S/4HANA Cloud Public Edition all versions