Skip to content

Commit 9b1f22b

Browse files
authored
fix: content-type charset (#415)
1 parent 3909fd4 commit 9b1f22b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/storage/storage.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ export class Storage {
237237
)
238238
}
239239

240-
if (!type.match(/^[a-zA-Z0-9\-\+]+\/([a-zA-Z0-9\-\+\.]+$)|\*$/)) {
240+
if (
241+
!type.match(/^([a-zA-Z0-9\-+.]+)\/([a-zA-Z0-9\-+.]+)(;\s*charset=[a-zA-Z0-9\-]+)?$|\*$/)
242+
) {
241243
throw new StorageBackendError(
242244
'invalid_mime_type',
243245
422,

src/storage/uploader.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,13 @@ export class Uploader {
226226
continue
227227
}
228228

229-
if (allowedMime[0] === type && allowedMime[1] === '*') {
229+
const [allowedType, allowedExtension] = allowedMime
230+
231+
if (allowedType === type && allowedExtension === '*') {
230232
return true
231233
}
232234

233-
if (allowedMime[0] === type && allowedMime[1] === ext) {
235+
if (allowedType === type && allowedExtension === ext) {
234236
return true
235237
}
236238
}
@@ -267,7 +269,8 @@ export class Uploader {
267269
const cacheTime = formData.fields.cacheControl?.value
268270

269271
body = formData.file
270-
mimeType = formData.mimetype
272+
/* @ts-expect-error: https://github.com/aws/aws-sdk-js-v3/issues/2085 */
273+
mimeType = formData.fields.contentType?.value || formData.mimetype
271274
cacheControl = cacheTime ? `max-age=${cacheTime}` : 'no-cache'
272275
isTruncated = () => formData.file.truncated
273276
} catch (e) {

0 commit comments

Comments
 (0)