@dimah-s3/react 1.7.1 → 2.0.0-beta.1
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/README.md +53 -13
- package/dist/api.d.ts +24 -15
- package/dist/api.d.ts.map +1 -1
- package/dist/chunk-SPUUNLXI.js +824 -0
- package/dist/chunk-SPUUNLXI.js.map +1 -0
- package/dist/create-s3-client.d.ts +1 -1
- package/dist/create-s3-client.d.ts.map +1 -1
- package/dist/engine.d.ts +15 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +204 -512
- package/dist/engine.js.map +1 -1
- package/dist/helpers/format-accept-labels.d.ts +15 -2
- package/dist/helpers/format-accept-labels.d.ts.map +1 -1
- package/dist/helpers/format-date.d.ts +7 -0
- package/dist/helpers/format-date.d.ts.map +1 -0
- package/dist/helpers/format-dimah-error.d.ts +12 -2
- package/dist/helpers/format-dimah-error.d.ts.map +1 -1
- package/dist/helpers/format-file-size.d.ts +20 -0
- package/dist/helpers/format-file-size.d.ts.map +1 -0
- package/dist/helpers/format-speed.d.ts +1 -1
- package/dist/helpers/format-speed.d.ts.map +1 -1
- package/dist/helpers/format-upload-progress.d.ts +1 -1
- package/dist/helpers/format-upload-progress.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +5 -8
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/load-route-catalog.d.ts +32 -8
- package/dist/helpers/load-route-catalog.d.ts.map +1 -1
- package/dist/helpers/throttled-speed.d.ts +2 -2
- package/dist/helpers/throttled-speed.d.ts.map +1 -1
- package/dist/helpers/to-timestamp.d.ts +5 -0
- package/dist/helpers/to-timestamp.d.ts.map +1 -0
- package/dist/helpers/truncate-file-name.d.ts +8 -0
- package/dist/helpers/truncate-file-name.d.ts.map +1 -0
- package/dist/helpers/use-format-accept-labels.d.ts +12 -0
- package/dist/helpers/use-format-accept-labels.d.ts.map +1 -0
- package/dist/helpers/use-format-eta.d.ts +14 -0
- package/dist/helpers/use-format-eta.d.ts.map +1 -0
- package/dist/helpers/use-format-speed.d.ts +12 -0
- package/dist/helpers/use-format-speed.d.ts.map +1 -0
- package/dist/hooks/use-delete.d.ts +6 -44
- package/dist/hooks/use-delete.d.ts.map +1 -1
- package/dist/hooks/use-download.d.ts +7 -117
- package/dist/hooks/use-download.d.ts.map +1 -1
- package/dist/hooks/use-fetch-download.d.ts +8 -0
- package/dist/hooks/use-fetch-download.d.ts.map +1 -0
- package/dist/hooks/use-file-intake.d.ts +43 -29
- package/dist/hooks/use-file-intake.d.ts.map +1 -1
- package/dist/hooks/use-file-upload.d.ts +38 -34
- package/dist/hooks/use-file-upload.d.ts.map +1 -1
- package/dist/hooks/use-object-list-selection.d.ts +78 -0
- package/dist/hooks/use-object-list-selection.d.ts.map +1 -0
- package/dist/hooks/use-object-list.d.ts +66 -16
- package/dist/hooks/use-object-list.d.ts.map +1 -1
- package/dist/hooks/use-object-url.d.ts +27 -10
- package/dist/hooks/use-object-url.d.ts.map +1 -1
- package/dist/hooks/use-route-upload-policy.d.ts +22 -14
- package/dist/hooks/use-route-upload-policy.d.ts.map +1 -1
- package/dist/hooks/use-upload.d.ts +72 -65
- package/dist/hooks/use-upload.d.ts.map +1 -1
- package/dist/index.d.ts +15 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2420 -2164
- package/dist/index.js.map +1 -1
- package/dist/internal/abortable.d.ts +9 -0
- package/dist/internal/abortable.d.ts.map +1 -0
- package/dist/internal/browser-download.d.ts +15 -0
- package/dist/internal/browser-download.d.ts.map +1 -0
- package/dist/internal/callbacks.d.ts +54 -0
- package/dist/internal/callbacks.d.ts.map +1 -0
- package/dist/internal/client-error.d.ts +15 -0
- package/dist/internal/client-error.d.ts.map +1 -0
- package/dist/internal/hooks.d.ts +27 -0
- package/dist/internal/hooks.d.ts.map +1 -0
- package/dist/internal/lru.d.ts +13 -0
- package/dist/internal/lru.d.ts.map +1 -0
- package/dist/internal/operations.d.ts +74 -0
- package/dist/internal/operations.d.ts.map +1 -0
- package/dist/internal/pool.d.ts +8 -0
- package/dist/internal/pool.d.ts.map +1 -0
- package/dist/list/entries.d.ts +14 -0
- package/dist/list/entries.d.ts.map +1 -0
- package/dist/list/memory-object-source.d.ts +60 -0
- package/dist/list/memory-object-source.d.ts.map +1 -0
- package/dist/list/types.d.ts +123 -11
- package/dist/list/types.d.ts.map +1 -1
- package/dist/s3-provider.d.ts +3 -2
- package/dist/s3-provider.d.ts.map +1 -1
- package/dist/store/local-storage-store.d.ts +5 -4
- package/dist/store/local-storage-store.d.ts.map +1 -1
- package/dist/store/memory-store.d.ts +3 -4
- package/dist/store/memory-store.d.ts.map +1 -1
- package/dist/translations/types.d.ts +105 -23
- package/dist/translations/types.d.ts.map +1 -1
- package/dist/types/delete.d.ts +98 -9
- package/dist/types/delete.d.ts.map +1 -1
- package/dist/types/download.d.ts +152 -23
- package/dist/types/download.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/operation.d.ts +38 -0
- package/dist/types/operation.d.ts.map +1 -0
- package/dist/types/upload-store.d.ts +30 -40
- package/dist/types/upload-store.d.ts.map +1 -1
- package/dist/types/upload.d.ts +177 -130
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort.d.ts +10 -0
- package/dist/upload/abort.d.ts.map +1 -0
- package/dist/upload/constants.d.ts +8 -3
- package/dist/upload/constants.d.ts.map +1 -1
- package/dist/upload/index.d.ts +3 -2
- package/dist/upload/index.d.ts.map +1 -1
- package/dist/upload/multipart.d.ts +14 -4
- package/dist/upload/multipart.d.ts.map +1 -1
- package/dist/upload/part-pool.d.ts +16 -0
- package/dist/upload/part-pool.d.ts.map +1 -0
- package/dist/upload/presigned-http.d.ts +5 -14
- package/dist/upload/presigned-http.d.ts.map +1 -1
- package/dist/upload/progress.d.ts +7 -0
- package/dist/upload/progress.d.ts.map +1 -0
- package/dist/upload/request.d.ts +9 -0
- package/dist/upload/request.d.ts.map +1 -0
- package/dist/upload/resume-key.d.ts +7 -3
- package/dist/upload/resume-key.d.ts.map +1 -1
- package/dist/upload/retry.d.ts +27 -2
- package/dist/upload/retry.d.ts.map +1 -1
- package/dist/upload/stored-upload.d.ts +7 -0
- package/dist/upload/stored-upload.d.ts.map +1 -0
- package/dist/upload/upload-file.d.ts +10 -11
- package/dist/upload/upload-file.d.ts.map +1 -1
- package/dist/upload/upload-part.d.ts +6 -3
- package/dist/upload/upload-part.d.ts.map +1 -1
- package/dist/upload/xhr-upload.d.ts +10 -2
- package/dist/upload/xhr-upload.d.ts.map +1 -1
- package/package.json +7 -8
- package/dist/helpers/format-eta.d.ts +0 -13
- package/dist/helpers/format-eta.d.ts.map +0 -1
- package/dist/helpers/format-validate-file-error.d.ts +0 -9
- package/dist/helpers/format-validate-file-error.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/internal-helpers.d.ts +0 -10
- package/dist/internal-helpers.d.ts.map +0 -1
- package/dist/store/use-immer-state.d.ts +0 -8
- package/dist/store/use-immer-state.d.ts.map +0 -1
- package/dist/types/error.d.ts +0 -27
- package/dist/types/error.d.ts.map +0 -1
- package/dist/upload/upload-files.d.ts +0 -26
- package/dist/upload/upload-files.d.ts.map +0 -1
|
@@ -1,47 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* What must be persisted to resume a multipart upload. The engine writes one
|
|
3
|
+
* record after `multipart.init` and deletes it once the upload completes or
|
|
4
|
+
* is cancelled.
|
|
3
5
|
*/
|
|
4
6
|
export type StoredUpload = {
|
|
5
7
|
/**
|
|
6
|
-
* Client-side resume identity
|
|
7
|
-
*
|
|
8
|
+
* Client-side resume identity from `multipartResumeKey`: the route, the
|
|
9
|
+
* file, and the request's name, type and metadata.
|
|
8
10
|
*/
|
|
9
11
|
resumeKey: string;
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
+
/** Upload ticket from `multipart.init`. Every later multipart call sends it. */
|
|
13
|
+
ticket: string;
|
|
12
14
|
/** Server-generated S3 object key. */
|
|
13
15
|
key: string;
|
|
14
|
-
/**
|
|
16
|
+
/** S3 multipart `UploadId`. */
|
|
17
|
+
uploadId: string;
|
|
18
|
+
/** Total file size in bytes, so a different file is never resumed. */
|
|
15
19
|
fileSize: number;
|
|
20
|
+
/** Part size the server chose, in bytes. */
|
|
21
|
+
partSize: number;
|
|
22
|
+
/** Number of parts the server chose. */
|
|
23
|
+
partCount: number;
|
|
24
|
+
/** Whether every part must send a SHA-256 checksum. */
|
|
25
|
+
checksum: boolean;
|
|
16
26
|
};
|
|
17
27
|
/**
|
|
18
|
-
* Storage backend for resumable multipart uploads
|
|
19
|
-
*
|
|
20
|
-
* Implement
|
|
21
|
-
*
|
|
22
|
-
* `localStorage` via `createLocalStorageStore()`.
|
|
28
|
+
* Storage backend for resumable multipart uploads, looked up by
|
|
29
|
+
* {@link StoredUpload.resumeKey}. `createLocalStorageStore()` and
|
|
30
|
+
* `createMemoryStore()` are built in. Implement it to keep uploads in any
|
|
31
|
+
* other storage, such as IndexedDB or a database.
|
|
23
32
|
*
|
|
24
|
-
*
|
|
33
|
+
* The engine ignores and deletes a record that is not a valid
|
|
34
|
+
* {@link StoredUpload}, such as one written by 1.x.
|
|
25
35
|
*
|
|
26
36
|
* @example
|
|
27
37
|
* ```ts
|
|
28
38
|
* const dbStore: UploadStore = {
|
|
29
39
|
* async get(resumeKey, fileSize) {
|
|
30
|
-
*
|
|
31
|
-
* return row
|
|
32
|
-
* ? {
|
|
33
|
-
* resumeKey,
|
|
34
|
-
* uploadId: row.uploadId,
|
|
35
|
-
* key: row.key,
|
|
36
|
-
* fileSize,
|
|
37
|
-
* }
|
|
38
|
-
* : null;
|
|
40
|
+
* return (await db.uploads.findFirst({ where: { resumeKey, fileSize } })) ?? null;
|
|
39
41
|
* },
|
|
40
42
|
* async set(upload) {
|
|
41
|
-
* await db.uploads.upsert({
|
|
42
|
-
* where: { resumeKey: upload.resumeKey },
|
|
43
|
-
* data: upload,
|
|
44
|
-
* });
|
|
43
|
+
* await db.uploads.upsert({ where: { resumeKey: upload.resumeKey }, data: upload });
|
|
45
44
|
* },
|
|
46
45
|
* async delete(resumeKey) {
|
|
47
46
|
* await db.uploads.deleteMany({ where: { resumeKey } });
|
|
@@ -50,20 +49,11 @@ export type StoredUpload = {
|
|
|
50
49
|
* ```
|
|
51
50
|
*/
|
|
52
51
|
export type UploadStore = {
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* Persist a new upload state after `CreateMultipartUpload` succeeds.
|
|
60
|
-
* Called once per upload, before any parts are sent.
|
|
61
|
-
*/
|
|
62
|
-
set: (upload: StoredUpload) => void | Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Remove the upload state after the upload completes or is explicitly
|
|
65
|
-
* abandoned. Should be a no-op if the key is not found.
|
|
66
|
-
*/
|
|
67
|
-
delete: (resumeKey: string) => void | Promise<void>;
|
|
52
|
+
/** The pending upload for this resume identity and file size, or `null`. */
|
|
53
|
+
get(resumeKey: string, fileSize: number): StoredUpload | null | Promise<StoredUpload | null>;
|
|
54
|
+
/** Saves an upload after `multipart.init`, before any part is sent. */
|
|
55
|
+
set(upload: StoredUpload): void | Promise<void>;
|
|
56
|
+
/** Removes an upload. Does nothing when the key is unknown. */
|
|
57
|
+
delete(resumeKey: string): void | Promise<void>;
|
|
68
58
|
};
|
|
69
59
|
//# sourceMappingURL=upload-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-store.d.ts","sourceRoot":"","sources":["../../src/types/upload-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload-store.d.ts","sourceRoot":"","sources":["../../src/types/upload-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,4EAA4E;IAC5E,GAAG,CACD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACtD,uEAAuE;IACvE,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,+DAA+D;IAC/D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD,CAAC"}
|
package/dist/types/upload.d.ts
CHANGED
|
@@ -1,173 +1,220 @@
|
|
|
1
|
-
import type { APIError, S3RouteName, UploadPresignResponse } from "@dimah-s3/core";
|
|
1
|
+
import type { APIError, ConfirmedObjectResponse, S3Api, S3RouteName, UploadPresignResponse } from "@dimah-s3/core";
|
|
2
|
+
import type { TransferProgress } from "./operation";
|
|
2
3
|
import type { UploadStore } from "./upload-store";
|
|
3
|
-
/**
|
|
4
|
-
export type UploadResult =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
/** The verified object after a successful upload (from HeadObject). */
|
|
5
|
+
export type UploadResult = ConfirmedObjectResponse;
|
|
6
|
+
/** Per-upload options sent to the presign API. */
|
|
7
|
+
export type UploadRequestOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Client extras sent to the server `object` callback as `clientMetadata`.
|
|
10
|
+
* Not written to S3 unless the route copies them into `object().metadata`.
|
|
11
|
+
*/
|
|
12
|
+
metadata?: Record<string, string>;
|
|
13
|
+
/** Overrides the browser's content type. */
|
|
12
14
|
contentType?: string;
|
|
13
|
-
/**
|
|
15
|
+
/** Overrides the browser's file name. */
|
|
14
16
|
fileName?: string;
|
|
15
17
|
};
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Request options for every file, or a function that returns them per file.
|
|
20
|
+
* A throw from the function fails that file with `HOOK_FAILED`.
|
|
21
|
+
*/
|
|
22
|
+
export type UploadRequestInput = UploadRequestOptions | ((file: File) => UploadRequestOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Options for one `handleFiles` call. Call `uploadOptions` shallow-merge over
|
|
25
|
+
* the hook's: call fields win, and `metadata` merges key by key.
|
|
26
|
+
*/
|
|
27
|
+
export type UploadCallOptions = {
|
|
28
|
+
uploadOptions?: UploadRequestInput;
|
|
29
|
+
/** Lowers `maxFiles` for this call. */
|
|
30
|
+
maxFiles?: number;
|
|
26
31
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
/** Where one file is in its upload. */
|
|
33
|
+
export type UploadFilePhase = "queued" | "preparing" | "presigning" | "uploading" | "finalizing" | "success" | "error";
|
|
34
|
+
/** The phases `uploadFile` reports while a file is in flight. */
|
|
35
|
+
export type UploadEnginePhase = Extract<UploadFilePhase, "preparing" | "presigning" | "uploading" | "finalizing">;
|
|
36
|
+
/** The phase of the whole upload queue. */
|
|
37
|
+
export type UploadPhase = "idle" | "uploading" | "success" | "error";
|
|
38
|
+
/** Display metadata for a file in upload UI. */
|
|
31
39
|
export type UploadFileInfo = {
|
|
32
|
-
|
|
33
|
-
name: string;
|
|
40
|
+
fileName: string;
|
|
34
41
|
/** File size in bytes. */
|
|
35
|
-
|
|
42
|
+
fileSize: number;
|
|
36
43
|
/** MIME type from the browser `File`. */
|
|
37
|
-
|
|
44
|
+
contentType: string;
|
|
38
45
|
/**
|
|
39
|
-
* Object URL for an image thumbnail, or `null` for
|
|
40
|
-
*
|
|
46
|
+
* Object URL for an image thumbnail, or `null` for other files. The upload
|
|
47
|
+
* hooks create and revoke it, so do not revoke it yourself.
|
|
41
48
|
*/
|
|
42
49
|
previewUrl: string | null;
|
|
43
50
|
};
|
|
44
|
-
/**
|
|
51
|
+
/** One file in the `useUpload` queue. */
|
|
45
52
|
export type UploadFileState = UploadFileInfo & {
|
|
46
|
-
/** Unique ID for this file in the
|
|
53
|
+
/** Unique ID for this file in the queue. Pass it to `cancel(id)`. */
|
|
47
54
|
id: string;
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
file: File;
|
|
56
|
+
phase: UploadFilePhase;
|
|
57
|
+
progress: TransferProgress;
|
|
50
58
|
error: APIError | null;
|
|
51
59
|
/** Set after this file succeeds. */
|
|
52
60
|
result: UploadResult | null;
|
|
53
61
|
};
|
|
54
|
-
/**
|
|
55
|
-
export type
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Unpadded base64 SHA-256. Sent when the route sets `upload.checksum`.
|
|
70
|
-
* The engine computes this when {@link FileUploadConfig.checksum} is true.
|
|
71
|
-
*/
|
|
72
|
-
checksum?: string;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Lifecycle hooks for `useUpload`.
|
|
76
|
-
* Callbacks that receive `File[]` / `UploadResult[]` always use arrays
|
|
77
|
-
* (a single file is `[file]` / `[result]`).
|
|
78
|
-
*/
|
|
79
|
-
export type UploadHooks = {
|
|
80
|
-
/** Runs before the upload starts. Return `false` to block it. */
|
|
81
|
-
beforeUpload?: (files: File[]) => Promise<boolean> | boolean;
|
|
82
|
-
/** Fires after validation passes and the upload begins. */
|
|
83
|
-
onUploadStart?: (files: File[]) => void;
|
|
84
|
-
/** Fires continuously with aggregate progress across the batch. */
|
|
85
|
-
onProgress?: (progress: UploadProgress) => void;
|
|
86
|
-
/** Fires continuously for one file while its bytes are transferred. */
|
|
87
|
-
onFileProgress?: (file: File, progress: UploadProgress) => void;
|
|
88
|
-
/** Fires after each part is successfully uploaded to S3 (multipart only). */
|
|
89
|
-
onPartUpload?: (file: File, partNumber: number, totalParts: number) => void;
|
|
90
|
-
/** Fires once after `CreateMultipartUpload` succeeds (multipart only). */
|
|
91
|
-
onMultipartInit?: (file: File, uploadId: string) => void;
|
|
92
|
-
/** Fires when one file in the batch finishes successfully. */
|
|
93
|
-
onFileSuccess?: (file: File, result: UploadResult) => void;
|
|
94
|
-
/** Fires when one file in the batch fails. */
|
|
95
|
-
onFileError?: (file: File, error: APIError) => void;
|
|
96
|
-
/** Fires when every file in the batch succeeds. */
|
|
97
|
-
onSuccess?: (results: UploadResult[]) => Promise<void> | void;
|
|
98
|
-
/** Fires when the batch fails (validation, block, or one or more file errors). */
|
|
99
|
-
onError?: (error: unknown, phase: UploadPhase) => void;
|
|
100
|
-
/** Fires when the upload is cancelled via `cancel()`. */
|
|
101
|
-
onCancel?: () => void;
|
|
62
|
+
/** How every file of one `handleFiles` call ended. */
|
|
63
|
+
export type UploadBatchResult = {
|
|
64
|
+
uploaded: {
|
|
65
|
+
file: File;
|
|
66
|
+
result: UploadResult;
|
|
67
|
+
}[];
|
|
68
|
+
failed: {
|
|
69
|
+
file: File;
|
|
70
|
+
error: APIError;
|
|
71
|
+
}[];
|
|
72
|
+
/** Files a `beforeUpload` callback blocked. */
|
|
73
|
+
blocked: File[];
|
|
74
|
+
/** Files cancelled or detached before they finished. */
|
|
75
|
+
aborted: File[];
|
|
102
76
|
};
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export type UploadTransport = (file: File, presign: UploadPresignResponse, options: {
|
|
108
|
-
onProgress?: (progress: UploadProgress) => void;
|
|
109
|
-
signal?: AbortSignal;
|
|
110
|
-
}) => Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Custom `S3Api` objects may set this to handle the byte transfer instead of
|
|
113
|
-
* uploading to the presigned URL.
|
|
114
|
-
*/
|
|
115
|
-
export type S3ApiUploadTransport = {
|
|
116
|
-
uploadTransport?: UploadTransport;
|
|
77
|
+
/** A file rejected before upload, such as for its type, size or count. */
|
|
78
|
+
export type FileRejection = {
|
|
79
|
+
file: File;
|
|
80
|
+
errors: readonly APIError[];
|
|
117
81
|
};
|
|
118
|
-
/** Retry
|
|
82
|
+
/** Retry settings for failed network requests. */
|
|
119
83
|
export type RetryConfig = {
|
|
120
|
-
/**
|
|
84
|
+
/** Retries per request after the first attempt. @default 3 */
|
|
121
85
|
maxRetries?: number;
|
|
122
86
|
/** Base delay in ms for exponential backoff. @default 1000 */
|
|
123
87
|
baseDelay?: number;
|
|
124
88
|
};
|
|
125
|
-
/**
|
|
126
|
-
export type
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*/
|
|
89
|
+
/** Options for `useUpload`. */
|
|
90
|
+
export type UseUploadOptions = {
|
|
91
|
+
/** Optional when an `<S3Provider>` is in the tree. */
|
|
92
|
+
api?: S3Api;
|
|
93
|
+
/** Named server route. The server builds the object key from its policy. */
|
|
131
94
|
route: S3RouteName;
|
|
132
95
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* The threshold is not configurable.
|
|
96
|
+
* HTML `accept` tokens: MIME types (`image/*`) and extensions (`.pdf`).
|
|
97
|
+
* Narrows the route's `fileTypes`; the server still enforces the route.
|
|
136
98
|
*/
|
|
99
|
+
accept?: readonly string[];
|
|
100
|
+
/** Max file size in bytes. The smaller of this and the route's wins. */
|
|
101
|
+
maxFileSize?: number;
|
|
102
|
+
/** Max files per selection. @default 1 */
|
|
103
|
+
maxFiles?: number;
|
|
104
|
+
/** `false` disables multipart even when the route allows it. */
|
|
137
105
|
multipart?: boolean;
|
|
106
|
+
/** Files uploaded at once. @default 2 */
|
|
107
|
+
concurrentFiles?: number;
|
|
108
|
+
/** Multipart parts uploaded at once per file. @default 4 */
|
|
109
|
+
concurrentParts?: number;
|
|
110
|
+
retry?: RetryConfig;
|
|
111
|
+
/** Persists multipart uploads so they can resume after a reload. */
|
|
112
|
+
uploadStore?: UploadStore;
|
|
113
|
+
/** Request options for every file. A call's `uploadOptions` merge over them. */
|
|
114
|
+
uploadOptions?: UploadRequestInput;
|
|
138
115
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
116
|
+
* `true` appends new files to the queue instead of replacing it. Without it,
|
|
117
|
+
* a new call cancels the calls still preparing, and replaces the queue once
|
|
118
|
+
* its files start uploading. A call that is blocked, rejected or fails
|
|
119
|
+
* before uploading leaves the queue alone.
|
|
120
|
+
* @default false
|
|
142
121
|
*/
|
|
143
|
-
|
|
122
|
+
queue?: boolean;
|
|
144
123
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
124
|
+
* Disables every intake interaction: the root, drop targets and paste, and
|
|
125
|
+
* `open()` does nothing. `handleFiles` still uploads what it is given.
|
|
147
126
|
*/
|
|
148
|
-
|
|
127
|
+
disabled?: boolean;
|
|
128
|
+
/** Disables drag and drop on the root. */
|
|
129
|
+
noDrag?: boolean;
|
|
130
|
+
/** Disables click-to-open on the root. */
|
|
131
|
+
noClick?: boolean;
|
|
132
|
+
/** Disables keyboard activation on the root. */
|
|
133
|
+
noKeyboard?: boolean;
|
|
134
|
+
/** Runs once per call. Return `false` to block it. */
|
|
135
|
+
beforeUpload?: (files: readonly File[]) => boolean | Promise<boolean>;
|
|
136
|
+
/** Runs once per call, after `beforeUpload` allows it. */
|
|
137
|
+
onUploadStart?: (files: readonly File[]) => void;
|
|
138
|
+
/** Byte progress of one file. */
|
|
139
|
+
onProgress?: (progress: TransferProgress, file: File) => void;
|
|
140
|
+
/** Runs after each multipart part is uploaded. */
|
|
141
|
+
onPartUpload?: (part: {
|
|
142
|
+
partNumber: number;
|
|
143
|
+
totalParts: number;
|
|
144
|
+
}, file: File) => void;
|
|
145
|
+
/** Runs once a multipart upload has started or resumed. */
|
|
146
|
+
onMultipartInit?: (session: {
|
|
147
|
+
uploadId: string;
|
|
148
|
+
key: string;
|
|
149
|
+
}, file: File) => void;
|
|
149
150
|
/**
|
|
150
|
-
*
|
|
151
|
+
* Runs once per uploaded file, after every file of the call has ended and
|
|
152
|
+
* every `onError` of the call has run.
|
|
151
153
|
*/
|
|
152
|
-
|
|
154
|
+
onSuccess?: (result: UploadResult, file: File) => void | Promise<void>;
|
|
155
|
+
/** Runs once per failed file, after every file of the call has ended. */
|
|
156
|
+
onError?: (error: APIError, file: File) => void;
|
|
157
|
+
/**
|
|
158
|
+
* Runs once per call, after every other callback, including a call with
|
|
159
|
+
* no valid file.
|
|
160
|
+
*/
|
|
161
|
+
onSettled?: (result: UploadBatchResult) => void | Promise<void>;
|
|
162
|
+
/** Runs with the files rejected before upload. */
|
|
163
|
+
onFileReject?: (rejections: readonly FileRejection[]) => void;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Replaces the PUT or POST to `presign.url` for single-shot uploads, such as
|
|
167
|
+
* for an in-memory backend. It must send `presign.fields` or
|
|
168
|
+
* `presign.headers` exactly, and reject with an `APIError` so the engine can
|
|
169
|
+
* retry: `UPLOAD_FAILED` with S3's status, `CHECKSUM_MISMATCH` when S3
|
|
170
|
+
* rejects the bytes' checksum (never retried), or `NETWORK_ERROR`.
|
|
171
|
+
*/
|
|
172
|
+
export type UploadTransport = (file: File, presign: UploadPresignResponse, options: {
|
|
173
|
+
onProgress?: (progress: TransferProgress) => void;
|
|
174
|
+
signal?: AbortSignal;
|
|
175
|
+
}) => Promise<void>;
|
|
176
|
+
/** An `S3Api` may set this to replace the default byte transfer. */
|
|
177
|
+
export type S3ApiUploadTransport = {
|
|
178
|
+
uploadTransport?: UploadTransport;
|
|
179
|
+
};
|
|
180
|
+
/** Options for `uploadFile`. */
|
|
181
|
+
export type UploadFileOptions = {
|
|
182
|
+
route: S3RouteName;
|
|
153
183
|
/**
|
|
154
|
-
*
|
|
155
|
-
* `
|
|
184
|
+
* What the route allows. Multipart is used for files of at least
|
|
185
|
+
* `DEFAULT_MULTIPART_THRESHOLD` bytes when `multipart` is true. A single-shot
|
|
186
|
+
* upload sends a SHA-256 checksum when `checksum` is true; multipart
|
|
187
|
+
* follows the init response instead.
|
|
156
188
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
189
|
+
policy: {
|
|
190
|
+
multipart: boolean;
|
|
191
|
+
checksum: boolean;
|
|
192
|
+
};
|
|
193
|
+
/** Parts uploaded at once. @default 4 */
|
|
159
194
|
concurrentParts?: number;
|
|
160
|
-
/** Number of files uploaded concurrently when `maxFiles` is greater than 1. */
|
|
161
|
-
concurrentFiles?: number;
|
|
162
|
-
/** Retry configuration for failed network requests. */
|
|
163
195
|
retry?: RetryConfig;
|
|
196
|
+
/** Persists multipart uploads so they can resume. */
|
|
197
|
+
uploadStore?: UploadStore;
|
|
198
|
+
request?: UploadRequestOptions;
|
|
164
199
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* - Omit / `undefined` — abort immediately on cancel or error.
|
|
168
|
-
* - `false` — same as omitting.
|
|
169
|
-
* - Custom `UploadStore` — persist `uploadId` across sessions.
|
|
200
|
+
* Aborts the upload. Abort with `uploadAbortReason("detach")` to keep a
|
|
201
|
+
* stored multipart upload for resuming; any other reason cancels it.
|
|
170
202
|
*/
|
|
171
|
-
|
|
203
|
+
signal?: AbortSignal;
|
|
204
|
+
onProgress?: (progress: TransferProgress) => void;
|
|
205
|
+
onPhaseChange?: (phase: UploadEnginePhase) => void;
|
|
206
|
+
onPartUpload?: (part: {
|
|
207
|
+
partNumber: number;
|
|
208
|
+
totalParts: number;
|
|
209
|
+
}) => void;
|
|
210
|
+
onMultipartInit?: (session: {
|
|
211
|
+
uploadId: string;
|
|
212
|
+
key: string;
|
|
213
|
+
}) => void;
|
|
172
214
|
};
|
|
215
|
+
/**
|
|
216
|
+
* Why an upload was aborted. `cancel` aborts the multipart upload and deletes
|
|
217
|
+
* its stored record. `detach` keeps both so the upload can resume.
|
|
218
|
+
*/
|
|
219
|
+
export type UploadAbortKind = "cancel" | "detach";
|
|
173
220
|
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/types/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EACX,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/types/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,uBAAuB,EACvB,KAAK,EACL,WAAW,EACX,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,uEAAuE;AACvE,MAAM,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAEnD,kDAAkD;AAClD,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAA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AAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACxE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UploadAbortKind } from "../types/upload.js";
|
|
2
|
+
/**
|
|
3
|
+
* The abort reason for an upload: an `AbortError` `DOMException` whose
|
|
4
|
+
* message is `kind`. Abort an upload's signal with it to pick what happens
|
|
5
|
+
* to a stored multipart upload.
|
|
6
|
+
*/
|
|
7
|
+
export declare function uploadAbortReason(kind: UploadAbortKind): DOMException;
|
|
8
|
+
/** The kind of an abort reason made by {@link uploadAbortReason}, else `null`. */
|
|
9
|
+
export declare function getUploadAbortKind(reason: unknown): UploadAbortKind | null;
|
|
10
|
+
//# sourceMappingURL=abort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../../src/upload/abort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,YAAY,CAErE;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAM1E"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
/** Files at least this large use multipart when the route allows it. */
|
|
1
2
|
export declare const DEFAULT_MULTIPART_THRESHOLD: number;
|
|
2
|
-
export declare const DEFAULT_PART_SIZE: number;
|
|
3
3
|
export declare const MAX_RETRIES = 3;
|
|
4
4
|
export declare const RETRY_BASE_DELAY = 1000;
|
|
5
|
-
export declare const DEFAULT_CONCURRENT_PARTS =
|
|
5
|
+
export declare const DEFAULT_CONCURRENT_PARTS = 4;
|
|
6
6
|
export declare const DEFAULT_CONCURRENT_FILES = 2;
|
|
7
|
-
/** Default max files per selection
|
|
7
|
+
/** Default max files per selection: one file. */
|
|
8
8
|
export declare const DEFAULT_MAX_FILES = 1;
|
|
9
|
+
/**
|
|
10
|
+
* A presigned URL counts as expired this long before its `expiresIn` ends,
|
|
11
|
+
* to allow for clock skew between the app server and S3.
|
|
12
|
+
*/
|
|
13
|
+
export declare const URL_EXPIRY_MARGIN_MS = 30000;
|
|
9
14
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/upload/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAC5D,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/upload/constants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAC5D,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AACtC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,iDAAiD;AACjD,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAAS,CAAC"}
|
package/dist/upload/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { uploadFile
|
|
2
|
-
export {
|
|
1
|
+
export { uploadFile } from "./upload-file";
|
|
2
|
+
export { getUploadAbortKind, uploadAbortReason } from "./abort";
|
|
3
3
|
export { multipartResumeKey } from "./resume-key";
|
|
4
|
+
export { mergeUploadRequest } from "./request";
|
|
4
5
|
export { DEFAULT_MULTIPART_THRESHOLD } from "./constants";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type MultipartInitPayload, type S3Api } from "@dimah-s3/core";
|
|
2
|
+
import type { UploadEnginePhase, UploadFileOptions, UploadResult } from "../types/upload.js";
|
|
3
|
+
/**
|
|
4
|
+
* Uploads `file` as a multipart upload in the layout the server picks at
|
|
5
|
+
* init, resuming a stored upload when `options.uploadStore` has one.
|
|
6
|
+
*
|
|
7
|
+
* With a store, a request error that may pass later (see
|
|
8
|
+
* {@link isRetryableError}) or an abort with `uploadAbortReason("detach")`
|
|
9
|
+
* keeps the server upload and its record for resuming. A cancel, any other
|
|
10
|
+
* abort, a failure that retrying cannot fix, or any failure without a store
|
|
11
|
+
* aborts the server upload and deletes the record. While one upload of a resume key runs, another upload of the
|
|
12
|
+
* same key runs without the store, so the two never share a session.
|
|
13
|
+
*/
|
|
14
|
+
export declare function uploadMultipart(api: S3Api, file: File, payload: MultipartInitPayload, options: UploadFileOptions, setPhase: (phase: UploadEnginePhase) => void): Promise<UploadResult>;
|
|
5
15
|
//# sourceMappingURL=multipart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/upload/multipart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/upload/multipart.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,KAAK,EACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACb,MAAM,gBAAgB,CAAC;AAoBxB;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,KAAK,EACV,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAC3C,OAAO,CAAC,YAAY,CAAC,CAcvB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type S3Api } from "@dimah-s3/core";
|
|
2
|
+
import type { UploadFileOptions } from "../types/upload.js";
|
|
3
|
+
import type { StoredUpload } from "../types/upload-store.js";
|
|
4
|
+
/** The server's part layout for one multipart upload. */
|
|
5
|
+
export type PartLayout = Pick<StoredUpload, "fileSize" | "partSize" | "partCount">;
|
|
6
|
+
/** Byte size of part `partNumber`. Only the last part may be smaller. */
|
|
7
|
+
export declare function layoutPartSize(layout: PartLayout, partNumber: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* Uploads every part of `upload` that is not in `done` through a pool of
|
|
10
|
+
* `concurrentParts` workers, following the server's layout. Each worker
|
|
11
|
+
* hashes its part as a stream when the upload requires checksums, signs it,
|
|
12
|
+
* and sends it with retries. The first failure aborts the parts still
|
|
13
|
+
* running and rejects with that failure.
|
|
14
|
+
*/
|
|
15
|
+
export declare function uploadParts(api: S3Api, file: File, upload: StoredUpload, done: ReadonlySet<number>, options: UploadFileOptions): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=part-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part-pool.d.ts","sourceRoot":"","sources":["../../src/upload/part-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAMzD,yDAAyD;AACzD,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,YAAY,EACZ,UAAU,GAAG,UAAU,GAAG,WAAW,CACtC,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAK7E;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,KAAK,EACV,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EACzB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAqEf"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UploadTransport } from "../types/upload.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* are embedded in `fields` and must be appended to the FormData **before** the
|
|
7
|
-
* file — this is an S3 requirement.
|
|
3
|
+
* The default {@link UploadTransport}. Sends `file` to the presigned URL with
|
|
4
|
+
* exactly the presign's PUT `headers`, or as a form with its POST `fields`
|
|
5
|
+
* first (S3 requires the fields before the file).
|
|
8
6
|
*/
|
|
9
|
-
export declare
|
|
10
|
-
/**
|
|
11
|
-
* Uploads a file directly to S3 using a presigned PUT URL.
|
|
12
|
-
*
|
|
13
|
-
* Use this when the server is configured with `method: "PUT"` — for
|
|
14
|
-
* example with Cloudflare R2 which does not support presigned POST.
|
|
15
|
-
*/
|
|
16
|
-
export declare function uploadPut(file: File, url: string, headers: Record<string, string>, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal): Promise<void>;
|
|
7
|
+
export declare const sendPresignedUpload: UploadTransport;
|
|
17
8
|
//# sourceMappingURL=presigned-http.d.ts.map
|