@aws-amplify/storage 6.9.5 → 6.9.6-unstable.0f5e997.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/providers/s3/apis/internal/uploadData/multipart/uploadCache.js +2 -1
- package/dist/cjs/providers/s3/apis/internal/uploadData/multipart/uploadCache.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/uploadData/multipart/uploadHandlers.js +4 -1
- package/dist/cjs/providers/s3/apis/internal/uploadData/multipart/uploadHandlers.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/uploadData/putObjectJob.js +4 -1
- package/dist/cjs/providers/s3/apis/internal/uploadData/putObjectJob.js.map +1 -1
- package/dist/cjs/providers/s3/utils/client/runtime/xhrTransferHandler.js +5 -1
- package/dist/cjs/providers/s3/utils/client/runtime/xhrTransferHandler.js.map +1 -1
- package/dist/cjs/utils/contentType.js +101 -0
- package/dist/cjs/utils/contentType.js.map +1 -0
- package/dist/esm/providers/s3/apis/internal/uploadData/multipart/uploadCache.mjs +2 -1
- package/dist/esm/providers/s3/apis/internal/uploadData/multipart/uploadCache.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/uploadData/multipart/uploadHandlers.mjs +4 -1
- package/dist/esm/providers/s3/apis/internal/uploadData/multipart/uploadHandlers.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/uploadData/putObjectJob.mjs +4 -1
- package/dist/esm/providers/s3/apis/internal/uploadData/putObjectJob.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/client/runtime/xhrTransferHandler.mjs +5 -1
- package/dist/esm/providers/s3/utils/client/runtime/xhrTransferHandler.mjs.map +1 -1
- package/dist/esm/utils/contentType.d.ts +4 -0
- package/dist/esm/utils/contentType.mjs +98 -0
- package/dist/esm/utils/contentType.mjs.map +1 -0
- package/package.json +117 -117
- package/src/providers/s3/apis/internal/uploadData/multipart/uploadCache.ts +2 -1
- package/src/providers/s3/apis/internal/uploadData/multipart/uploadHandlers.ts +4 -1
- package/src/providers/s3/apis/internal/uploadData/putObjectJob.ts +4 -1
- package/src/providers/s3/utils/client/runtime/xhrTransferHandler.ts +5 -1
- package/src/utils/contentType.ts +99 -0
|
@@ -38,6 +38,7 @@ import { logger } from '../../../../../../utils';
|
|
|
38
38
|
import { calculateContentCRC32 } from '../../../../utils/crc32';
|
|
39
39
|
import { StorageOperationOptionsInput } from '../../../../../../types/inputs';
|
|
40
40
|
import { IntegrityError } from '../../../../../../errors/IntegrityError';
|
|
41
|
+
import { getContentType } from '../../../../../../utils/contentType';
|
|
41
42
|
|
|
42
43
|
import { uploadPartExecutor } from './uploadPartExecutor';
|
|
43
44
|
import {
|
|
@@ -137,7 +138,9 @@ export const getMultipartUploadHandlers = (
|
|
|
137
138
|
const {
|
|
138
139
|
contentDisposition,
|
|
139
140
|
contentEncoding,
|
|
140
|
-
contentType =
|
|
141
|
+
contentType = uploadDataOptions?.contentType ??
|
|
142
|
+
getContentType(data, objectKey) ??
|
|
143
|
+
'application/octet-stream',
|
|
141
144
|
metadata,
|
|
142
145
|
preventOverwrite,
|
|
143
146
|
onProgress,
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from '../../../utils/constants';
|
|
23
23
|
import { calculateContentCRC32 } from '../../../utils/crc32';
|
|
24
24
|
import { constructContentDisposition } from '../../../utils/constructContentDisposition';
|
|
25
|
+
import { getContentType } from '../../../../../utils/contentType';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* The input interface for UploadData API with only the options needed for single part upload.
|
|
@@ -60,7 +61,9 @@ export const putObjectJob =
|
|
|
60
61
|
const {
|
|
61
62
|
contentDisposition,
|
|
62
63
|
contentEncoding,
|
|
63
|
-
contentType =
|
|
64
|
+
contentType = uploadDataOptions?.contentType ??
|
|
65
|
+
getContentType(data, objectKey) ??
|
|
66
|
+
'application/octet-stream',
|
|
64
67
|
preventOverwrite,
|
|
65
68
|
metadata,
|
|
66
69
|
checksumAlgorithm,
|
|
@@ -190,7 +190,11 @@ export const xhrTransferHandler: TransferHandler<
|
|
|
190
190
|
const convertToTransferProgressEvent = (
|
|
191
191
|
event: ProgressEvent,
|
|
192
192
|
): TransferProgressEvent => ({
|
|
193
|
-
|
|
193
|
+
// `loaded` can exceed the `total` in some cases due to platform issues/bugs e.g. React Native & Expo Android
|
|
194
|
+
// clamp `loaded` values down to `total` if possible.
|
|
195
|
+
transferredBytes: event.lengthComputable
|
|
196
|
+
? Math.min(event.loaded, event.total)
|
|
197
|
+
: event.loaded,
|
|
194
198
|
totalBytes: event.lengthComputable ? event.total : undefined,
|
|
195
199
|
});
|
|
196
200
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
const MIME_TYPES: Record<string, string> = {
|
|
5
|
+
// Audio
|
|
6
|
+
aac: 'audio/aac',
|
|
7
|
+
mid: 'audio/midi',
|
|
8
|
+
midi: 'audio/x-midi',
|
|
9
|
+
mp3: 'audio/mpeg',
|
|
10
|
+
oga: 'audio/ogg',
|
|
11
|
+
opus: 'audio/ogg',
|
|
12
|
+
wav: 'audio/wav',
|
|
13
|
+
weba: 'audio/webm',
|
|
14
|
+
// Video
|
|
15
|
+
avi: 'video/x-msvideo',
|
|
16
|
+
mp4: 'video/mp4',
|
|
17
|
+
mpeg: 'video/mpeg',
|
|
18
|
+
ogv: 'video/ogg',
|
|
19
|
+
ts: 'video/mp2t',
|
|
20
|
+
webm: 'video/webm',
|
|
21
|
+
// Images
|
|
22
|
+
apng: 'image/apng',
|
|
23
|
+
avif: 'image/avif',
|
|
24
|
+
bmp: 'image/bmp',
|
|
25
|
+
gif: 'image/gif',
|
|
26
|
+
ico: 'image/vnd.microsoft.icon',
|
|
27
|
+
jpeg: 'image/jpeg',
|
|
28
|
+
jpg: 'image/jpeg',
|
|
29
|
+
png: 'image/png',
|
|
30
|
+
svg: 'image/svg+xml',
|
|
31
|
+
tif: 'image/tiff',
|
|
32
|
+
tiff: 'image/tiff',
|
|
33
|
+
webp: 'image/webp',
|
|
34
|
+
// Text
|
|
35
|
+
css: 'text/css',
|
|
36
|
+
csv: 'text/csv',
|
|
37
|
+
htm: 'text/html',
|
|
38
|
+
html: 'text/html',
|
|
39
|
+
ics: 'text/calendar',
|
|
40
|
+
js: 'text/javascript',
|
|
41
|
+
md: 'text/markdown',
|
|
42
|
+
mjs: 'text/javascript',
|
|
43
|
+
txt: 'text/plain',
|
|
44
|
+
// Application
|
|
45
|
+
abw: 'application/x-abiword',
|
|
46
|
+
arc: 'application/x-freearc',
|
|
47
|
+
azw: 'application/vnd.amazon.ebook',
|
|
48
|
+
bin: 'application/octet-stream',
|
|
49
|
+
bz: 'application/x-bzip',
|
|
50
|
+
bz2: 'application/x-bzip2',
|
|
51
|
+
cda: 'application/x-cdf',
|
|
52
|
+
csh: 'application/x-csh',
|
|
53
|
+
doc: 'application/msword',
|
|
54
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
55
|
+
eot: 'application/vnd.ms-fontobject',
|
|
56
|
+
epub: 'application/epub+zip',
|
|
57
|
+
gz: 'application/gzip',
|
|
58
|
+
jar: 'application/java-archive',
|
|
59
|
+
json: 'application/json',
|
|
60
|
+
jsonld: 'application/ld+json',
|
|
61
|
+
mpkg: 'application/vnd.apple.installer+xml',
|
|
62
|
+
odp: 'application/vnd.oasis.opendocument.presentation',
|
|
63
|
+
ods: 'application/vnd.oasis.opendocument.spreadsheet',
|
|
64
|
+
odt: 'application/vnd.oasis.opendocument.text',
|
|
65
|
+
ogx: 'application/ogg',
|
|
66
|
+
pdf: 'application/pdf',
|
|
67
|
+
php: 'application/x-httpd-php',
|
|
68
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
69
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
70
|
+
rar: 'application/vnd.rar',
|
|
71
|
+
rtf: 'application/rtf',
|
|
72
|
+
sh: 'application/x-sh',
|
|
73
|
+
tar: 'application/x-tar',
|
|
74
|
+
vsd: 'application/vnd.visio',
|
|
75
|
+
webmanifest: 'application/manifest+json',
|
|
76
|
+
xhtml: 'application/xhtml+xml',
|
|
77
|
+
xls: 'application/vnd.ms-excel',
|
|
78
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
79
|
+
xml: 'application/xml',
|
|
80
|
+
zip: 'application/zip',
|
|
81
|
+
// Fonts
|
|
82
|
+
otf: 'font/otf',
|
|
83
|
+
ttf: 'font/ttf',
|
|
84
|
+
woff: 'font/woff',
|
|
85
|
+
woff2: 'font/woff2',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Detect content type from file data or filename extension
|
|
90
|
+
*/
|
|
91
|
+
export const getContentType = (data: any, key: string): string | undefined => {
|
|
92
|
+
if (data instanceof File && data.type) {
|
|
93
|
+
return data.type;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const ext = key.split('.').pop()?.toLowerCase();
|
|
97
|
+
|
|
98
|
+
return ext ? MIME_TYPES[ext] : undefined;
|
|
99
|
+
};
|