Possible bug in five.addAttachment() with XLSX attachments

Hi Five team,

I believe I may have found a bug in five.addAttachment() when attaching an XLSX file as a Base64 Data URI.

Issue summary

When using:

five.addAttachment(fileData, fileName);

with:

  • a valid XLSX Base64 Data URI
  • a filename ending with .xlsx

the attachment received by email does not preserve the supplied filename.

Expected filename

Honoraires-BBC-14.xlsx

Actual filename received

Honoraires-BBC-14.xlsx_591c3e7d2491de3fbc5301417a8ea799.octet-stream

The attached file itself is valid, but users cannot open it directly from their email because the .xlsx extension has effectively been replaced by .octet-stream. They must first download the attachment and manually rename it, which is a major issue for my application because users expect to be able to open the Excel attachment directly from their email.

Code used

const fileName = item.nom ? item.nom : (context.Subject + ".xlsx");

const fileData =
    "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," +
    excelData.base64;

five.log("fileName = " + fileName);
five.log("fileData prefix = " + fileData.substring(0,120));

five.addAttachment(fileData, fileName);

Additional information

I have already verified the following:

  • excelData.base64 starts with UEsDB..., which is the expected ZIP signature for a valid XLSX file.
  • The generated XLSX file is valid and opens correctly after manually renaming it to .xlsx.
  • The filename passed to five.addAttachment() is correct immediately before the call.
  • The Data URI uses the official XLSX MIME type:
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • PDF attachments generated with five.toDataURL('application/pdf', ...) preserve their filename correctly.
  • The issue appears to affect XLSX attachments only (or possibly manually-created Data URI attachments).

I could not find any documentation indicating that XLSX attachments are unsupported.

Is this a known limitation or a bug?

If needed, I can provide access to a deployed application that reproduces the issue.

Thank you!

Jean


Note: This post was written with the assistance of an AI to help describe the issue clearly in English. However, all observations, tests, logs, and code snippets are from my own application.

Hi Jean,

Thank you for bringing this question.

In this scenario, it seems that a MIME subtype is added to the filename, which changes:

from: Honoraires-BBC-14.xlsx

Into: Honoraires-BBC-14.xlsx_.octet-stream

An alternative solution is to use application/xlsx and pass the filename without the .xlsx extension:

let fileName = item.nom
    ? item.nom
    : context.Subject;

fileName = fileName.replace(/\.xlsx$/i, "");

const fileData =
    "data:application/xlsx;base64," +
    excelData.base64;

five.addAttachment(fileData, fileName);

Five will then generate a filename ending in .xlsx, for example:

Honoraires-BBC-14_.xlsx

The system-generated identifier may still be added, but the file will have the correct extension, and users should be able to open it directly in Excel.

Please, let me know how that goes.

Regards,
Elton S

Hi Elton,

Thank you, the workaround works!

The attachment is now received as:

Honoraires-BBC-14_b408592a65b9fcd48efbcb2f6da6abe3.xlsx

Yes, the system-generated identifier is added, but the file now has the correct .xlsx extension. My users will be happy to be able to open it directly in Excel.

Regards,
Jean

1 Like

Hi Jean,

I am glad to know that the solution worked well!

Regards,
Elton S