🐛 Fix URL encoded filename on download (#675)

* fix: #665 url encoded filename on download
* ♻️ back: refactor content-disposition attachment filename encoding (#665)

---------

Co-authored-by: Eric Doughty-Papassideris <edoughtypapassideris@linagora.com>
This commit is contained in:
Montassar Ghanmy
2024-10-03 13:43:33 +01:00
committed by GitHub
parent 7daac6cb8b
commit 32276edb5d
3 changed files with 18 additions and 5 deletions
@@ -22,3 +22,12 @@ export const fileIsMedia = (file: Partial<File>): boolean => {
file.metadata?.mime?.startsWith("image/")
);
};
/**
* Generate RFC 5987 UTF-8 encoding compliant header value for `Content-Disposition`
* to make a browser download a reponse to a file with the provided name
*/
export const formatAttachmentContentDispositionHeader = (filename: string) => {
const encoded = encodeURIComponent(filename.replace(/[^\p{L}0-9 _.-]/gu, ""));
return `attachment; filename="${encoded}"; filename*=UTF-8''${encoded}`;
};