File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,8 @@ export class AttachmentsService {
6767 Body : fileBuffer ,
6868 ContentType : uploadDto . fileType ,
6969 Metadata : {
70- originalFileName : uploadDto . fileName ,
70+ // S3 metadata becomes HTTP headers (x-amz-meta-*) and must be ASCII without control chars
71+ originalFileName : this . sanitizeHeaderValue ( uploadDto . fileName ) ,
7172 organizationId,
7273 entityId,
7374 entityType,
@@ -273,6 +274,18 @@ export class AttachmentsService {
273274 return fileName . replace ( / [ ^ a - z A - Z 0 - 9 . - ] / g, '_' ) ;
274275 }
275276
277+ /**
278+ * Sanitize header value for S3 user metadata (x-amz-meta-*) to avoid invalid characters
279+ * - Remove control characters (\x00-\x1F, \x7F)
280+ * - Replace non-ASCII with '_'
281+ * - Trim whitespace
282+ */
283+ private sanitizeHeaderValue ( value : string ) : string {
284+ const withoutControls = value . replace ( / [ \x00 - \x1F \x7F ] / g, '' ) ;
285+ const asciiOnly = withoutControls . replace ( / [ ^ \x20 - \x7E ] / g, '_' ) ;
286+ return asciiOnly . trim ( ) ;
287+ }
288+
276289 /**
277290 * Map MIME type to AttachmentType enum
278291 */
You can’t perform that action at this time.
0 commit comments