cancel
Showing results for 
Search instead for 
Did you mean: 

Convert PNG/JPG attachment to base64 and send it via business rule

zarnovickyf
Participant
0 Kudos
230

Hello FSM experts,

I need advice regarding an issue of converting PNG/JPG attachments to base64 format for integration purposes in SAP FSM. In my current setup, I use business rule to extract an attachment through the Get Attachment API, convert it to base64, and send it to another system via an API call. For the past 3 years, my way has worked fine. However, over the last few days, the base64 conversion has stopped work correctly—it seems to replace characters like 'i' with '/' and possibly more (e.g. MIME-type "iVBOR" (means PNG type) changed to "/VBOR").

At present, I am using JavaScript to handle the conversion directly within the second API call. I would like to ask the community: what methods or practices do you use to convert attachments to base64 in similar scenarios? Are there any reliable alternatives you use and work event these days?

Example of JS conversion to base64 is in attachment.

Thank you in advance for your insights!

Filip

Accepted Solutions (1)

Accepted Solutions (1)

zarnovickyf
Participant
0 Kudos

Solution from SAP Support, use new API to get attachment:

https://eu.fsm.cloud.sap/cloud-attachment-service/api/v1/Attachment/$ {attachment.id}/content?dtos=Attachment.18&account=${account.name}&company=${company.name}

instead of the previous version:

https://eu.coresuite.com/api/data/v4/Attachment/{attachment.id}/content?dtos=Attachment.18&account=${account.name}

Answers (1)

Answers (1)

diana45peters
Newcomer
0 Kudos

Hello! USPS Liteblue@zarnovickyf

Here's a high-level approach to troubleshooting and resolving the issue you're experiencing with converting PNG/JPG attachments to base64 in SAP FSM, without diving into code:

1. Check for System or Service Changes

Since this method has been working for years, the first thing to consider is whether there have been any recent updates to SAP FSM or the external systems you're integrating with. System updates, API changes, or updates to underlying libraries can sometimes affect how base64 encoding works.

  • Action: Review any release notes from SAP FSM to check if there have been any changes to the Get Attachment API or how base64-encoded data is handled.
  • Action: Check if any other systems or services that you integrate with (e.g., the system receiving the base64 data) have changed or updated their behavior.

2. Check the Encoding Consistency

The issue you're describing—where characters like 'i' get replaced by '/'—suggests there may be an encoding inconsistency, especially when the base64 data is transferred. It's possible that the encoding used to convert the attachment to base64 might not be the same on both sides of the integration (i.e., how SAP FSM and the receiving system are interpreting the data).

  • Action: Ensure that both SAP FSM and the receiving system are using the same character encoding (preferably UTF-8). Base64 encoding should be handled consistently across both systems to avoid discrepancies.
  • Action: Verify that the complete base64 string is being transferred. Sometimes, data truncation or encoding issues occur when the base64 string exceeds certain size limits or if there's a mismatch in how the data is being passed.

3. Ensure Proper MIME Type Handling

Base64-encoded files typically begin with a MIME type (e.g., data:image/png;base64,). If this part is missing or altered, the data might not be correctly recognized or decoded at the other end.

  • Action: Confirm that the MIME type (like data:image/png;base64,) is included with the base64 data. This is especially important if you're dealing with image files like PNG or JPG, as the MIME type helps the receiving system interpret the data correctly.

4. Verify the File Handling Process in SAP FSM

Since you're using SAP FSM to handle attachments, ensure that the attachment retrieval process is still functioning correctly. Sometimes, changes to how files are retrieved or processed might impact the integrity of the base64 encoding.

  • Action: Review the configuration and process for extracting attachments using the Get Attachment API to ensure that the entire file is being captured before it’s converted into base64 format.
  • Action: If you are applying any kind of transformation or manipulation to the file before encoding it (e.g., resizing or compressing images), check if those processes have introduced any errors.

5. Look for Data Corruption or Truncation During Transmission

If the base64 string is very large (for example, large images or attachments), it's possible that the data is being truncated or altered during transmission.

  • Action: Monitor the API requests and responses to ensure the full base64 string is being sent. Look for any signs that the data might be getting truncated or corrupted when transmitted between systems.

6. Use a Base64 Validation Tool

To check if the base64-encoded data is correct, you can use online base64 tools. These tools can help you verify whether the base64 encoding is correct and if the file, when decoded, matches the original image or file.

  • Action: Use a base64 validation tool like base64.guru, where you can input the base64 string and verify the decoded image to ensure it matches the original file.

7. Test with Different Attachments or Formats

Sometimes, specific file types or attachments might behave differently, especially if the files are large or have complex metadata.

  • Action: Test with a variety of smaller or simpler PNG/JPG images to determine if the issue is consistent across different file types. This can help narrow down whether the issue is related to specific file formats or sizes.

Best regards,
Diana Peters

zarnovickyf
Participant
0 Kudos

Hello Diana, thanks for your message, it helps us analyze the problem. The solution came from SAP Support, they gave us a new API to get Attachments that solved the problem:

https://eu.fsm.cloud.sap/cloud-attachment-service/api/v1/Attachment/${attachment.id}/content?dtos=Attachment.18&account=${account.name}&company=${company.name}

Until now we were using https://eu.coresuite.com/api/data/v4/Attachment/${attachment.id}/content?dtos=Attachment.18&account=${account.name}

Filip