@better-s3/react 3.1048.0 → 3.1050.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/README.md +12 -77
- package/dist/api.d.ts +3 -5
- package/dist/helpers/index.d.ts +0 -6
- package/dist/hooks/use-delete.d.ts +11 -3
- package/dist/hooks/use-download.d.ts +10 -5
- package/dist/hooks/use-fetch-download.d.ts +11 -2
- package/dist/hooks/use-multi-upload-controls.d.ts +9 -0
- package/dist/hooks/use-multi-upload.d.ts +11 -3
- package/dist/hooks/use-upload-controls.d.ts +9 -0
- package/dist/hooks/use-upload.d.ts +8 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +3 -88
- package/dist/index.js.map +1 -1
- package/dist/s3-provider.d.ts +6 -6
- package/dist/types/delete.d.ts +3 -0
- package/dist/types/download.d.ts +6 -0
- package/dist/types/index.d.ts +0 -1
- package/dist/types/multi-upload.d.ts +5 -0
- package/dist/types/upload.d.ts +28 -25
- package/dist/upload/multipart.d.ts +1 -1
- package/dist/upload/upload-file.d.ts +1 -1
- package/dist/upload/upload-files.d.ts +1 -1
- package/package.json +6 -3
- package/dist/helpers/build-object-key.d.ts +0 -20
- package/dist/helpers/format-file-size.d.ts +0 -11
- package/dist/helpers/get-file-extension.d.ts +0 -13
- package/dist/helpers/parse-content-disposition.d.ts +0 -18
- package/dist/helpers/truncate-filename.d.ts +0 -9
- package/dist/helpers/validate-file.d.ts +0 -22
- package/dist/types/s3-api.d.ts +0 -158
package/dist/s3-provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import type { S3Api } from "
|
|
2
|
+
import type { S3Api } from "@better-s3/core";
|
|
3
3
|
/**
|
|
4
4
|
* Internal context — use `S3Provider` to supply and `useS3Client` to consume.
|
|
5
5
|
* Exported so hooks can call `useContext(S3Context)` directly without throwing
|
|
@@ -15,7 +15,7 @@ export declare const S3Context: import("react").Context<S3Api | null>;
|
|
|
15
15
|
* @example
|
|
16
16
|
* ```tsx
|
|
17
17
|
* // With @better-s3/server:
|
|
18
|
-
* import { createS3Api } from "@better-s3/
|
|
18
|
+
* import { createS3Api } from "@better-s3/core";
|
|
19
19
|
* import { S3Provider } from "@better-s3/react";
|
|
20
20
|
*
|
|
21
21
|
* const s3Client = createS3Api();
|
|
@@ -24,10 +24,10 @@ export declare const S3Context: import("react").Context<S3Api | null>;
|
|
|
24
24
|
* return <S3Provider client={s3Client}>{children}</S3Provider>;
|
|
25
25
|
* }
|
|
26
26
|
*
|
|
27
|
-
* //
|
|
28
|
-
* import {
|
|
27
|
+
* // Custom base path:
|
|
28
|
+
* import { createS3Api } from "@better-s3/core";
|
|
29
29
|
*
|
|
30
|
-
* const s3Client =
|
|
30
|
+
* const s3Client = createS3Api("/api/my-s3");
|
|
31
31
|
*
|
|
32
32
|
* export function Providers({ children }: { children: React.ReactNode }) {
|
|
33
33
|
* return <S3Provider client={s3Client}>{children}</S3Provider>;
|
|
@@ -37,7 +37,7 @@ export declare const S3Context: import("react").Context<S3Api | null>;
|
|
|
37
37
|
export declare function S3Provider({ client, children, }: {
|
|
38
38
|
client: S3Api;
|
|
39
39
|
children: ReactNode;
|
|
40
|
-
}): import("react
|
|
40
|
+
}): import("react").JSX.Element;
|
|
41
41
|
/**
|
|
42
42
|
* Returns the `S3Api` client from the nearest `S3Provider`.
|
|
43
43
|
* Throws if called outside a provider and no `api` prop was given to the hook.
|
package/dist/types/delete.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type DeletePhase = "idle" | "confirming" | "deleting" | "success" | "error";
|
|
2
|
+
/** Lifecycle hooks for delete. */
|
|
2
3
|
export type DeleteHooks = {
|
|
4
|
+
/** Runs before delete. Return `false` to block it. */
|
|
3
5
|
beforeDelete?: (key: string) => Promise<boolean> | boolean;
|
|
6
|
+
/** Fires when delete begins (after confirmation). */
|
|
4
7
|
onDeleteStart?: (key: string) => void;
|
|
5
8
|
onSuccess?: (key: string) => Promise<void> | void;
|
|
6
9
|
onError?: (key: string, error: unknown, phase: DeletePhase) => void;
|
package/dist/types/download.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { UploadProgress } from "./upload";
|
|
2
2
|
export type DownloadPhase = "idle" | "presigning" | "error";
|
|
3
|
+
/** Lifecycle hooks for presign-and-navigate download. */
|
|
3
4
|
export type DownloadHooks = {
|
|
5
|
+
/** Runs before presigning. Return `false` to block the download. */
|
|
4
6
|
beforeDownload?: (key: string) => Promise<boolean> | boolean;
|
|
5
7
|
/** Fires as soon as the browser has been handed the URL — not when download completes. */
|
|
6
8
|
onInitiated?: (key: string) => void;
|
|
@@ -9,11 +11,15 @@ export type DownloadHooks = {
|
|
|
9
11
|
export type FetchDownloadPhase = "idle" | "presigning" | "downloading" | "success" | "error";
|
|
10
12
|
/** Identical shape to {@link UploadProgress}. */
|
|
11
13
|
export type FetchDownloadProgress = UploadProgress;
|
|
14
|
+
/** Lifecycle hooks for fetch-based download with progress. */
|
|
12
15
|
export type FetchDownloadHooks = {
|
|
16
|
+
/** Runs before presigning. Return `false` to block the download. */
|
|
13
17
|
beforeDownload?: (key: string) => Promise<boolean> | boolean;
|
|
18
|
+
/** Fires when the byte transfer begins. */
|
|
14
19
|
onDownloadStart?: (key: string) => void;
|
|
15
20
|
onProgress?: (key: string, progress: UploadProgress) => void;
|
|
16
21
|
onSuccess?: (key: string, fileName: string) => Promise<void> | void;
|
|
17
22
|
onError?: (key: string, error: unknown, phase: FetchDownloadPhase) => void;
|
|
23
|
+
/** Fires when cancelled via `cancel()`. */
|
|
18
24
|
onCancel?: (key: string) => void;
|
|
19
25
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { UploadProgress, UploadResult } from "./upload";
|
|
2
2
|
export type MultiUploadPhase = "idle" | "validating" | "uploading" | "success" | "error";
|
|
3
|
+
/** Per-file state in a multi-upload batch. */
|
|
3
4
|
export type MultiUploadFileState = {
|
|
5
|
+
/** Unique ID for this file in the batch. */
|
|
4
6
|
id: string;
|
|
7
|
+
/** Display file name. */
|
|
5
8
|
fileName: string;
|
|
9
|
+
/** File size in bytes. */
|
|
6
10
|
fileSize: number;
|
|
7
11
|
status: "pending" | "uploading" | "success" | "error";
|
|
8
12
|
progress: UploadProgress;
|
|
9
13
|
error: string | null;
|
|
10
14
|
};
|
|
15
|
+
/** Lifecycle hooks for multi-file upload. */
|
|
11
16
|
export type MultiUploadHooks = {
|
|
12
17
|
beforeUpload?: (files: File[]) => Promise<boolean> | boolean;
|
|
13
18
|
onUploadStart?: (files: File[]) => void;
|
package/dist/types/upload.d.ts
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
import type { UploadStore } from "./upload-store";
|
|
2
|
+
/** Result returned after a successful upload. */
|
|
2
3
|
export type UploadResult = {
|
|
4
|
+
/** S3 object key. */
|
|
3
5
|
key: string;
|
|
6
|
+
/** Public or presigned URL, when available. */
|
|
4
7
|
url?: string;
|
|
8
|
+
/** Object ETag from S3. */
|
|
5
9
|
eTag?: string;
|
|
6
10
|
};
|
|
11
|
+
/** Byte transfer progress for upload and fetch-download. */
|
|
7
12
|
export type UploadProgress = {
|
|
13
|
+
/** Bytes transferred so far. */
|
|
8
14
|
loaded: number;
|
|
15
|
+
/** Total bytes to transfer. */
|
|
9
16
|
total: number;
|
|
17
|
+
/** Progress percentage (0–100). */
|
|
10
18
|
percent: number;
|
|
11
19
|
/** Instantaneous transfer speed in bytes/second. `undefined` until measurable. */
|
|
12
20
|
speed?: number;
|
|
13
21
|
};
|
|
14
22
|
export type UploadPhase = "idle" | "validating" | "presigning" | "uploading" | "finalizing" | "success" | "error";
|
|
23
|
+
/** Per-upload options passed to the presign API. */
|
|
15
24
|
export type UploadRequestOptions = {
|
|
16
|
-
/** Custom S3 object metadata (x-amz-meta
|
|
25
|
+
/** Custom S3 object metadata (`x-amz-meta-*`). */
|
|
17
26
|
metadata?: Record<string, string>;
|
|
18
|
-
/** Target bucket (overrides server default) */
|
|
27
|
+
/** Target bucket (overrides server default). */
|
|
19
28
|
bucket?: string;
|
|
20
|
-
/** Override auto-detected content type */
|
|
29
|
+
/** Override auto-detected content type. */
|
|
21
30
|
contentType?: string;
|
|
22
|
-
/** Object ACL
|
|
31
|
+
/** Object ACL — defaults to `'private'`. */
|
|
23
32
|
acl?: "private" | "public-read";
|
|
24
33
|
/**
|
|
25
34
|
* Original file name stored as `Content-Disposition` on the S3 object.
|
|
@@ -33,6 +42,7 @@ export type UploadRequestOptions = {
|
|
|
33
42
|
*/
|
|
34
43
|
partSize?: number;
|
|
35
44
|
};
|
|
45
|
+
/** Lifecycle hooks for single-file upload. */
|
|
36
46
|
export type UploadHooks = {
|
|
37
47
|
/** Runs before the upload starts. Return `false` to block it. */
|
|
38
48
|
beforeUpload?: (file: File) => Promise<boolean> | boolean;
|
|
@@ -40,16 +50,9 @@ export type UploadHooks = {
|
|
|
40
50
|
onUploadStart?: (file: File, key: string) => void;
|
|
41
51
|
/** Fires continuously while bytes are transferred. */
|
|
42
52
|
onProgress?: (file: File, progress: UploadProgress) => void;
|
|
43
|
-
/**
|
|
44
|
-
* Fires after each part is successfully uploaded to S3.
|
|
45
|
-
* Only called during multipart uploads (files above `multipartThreshold`).
|
|
46
|
-
*/
|
|
53
|
+
/** Fires after each part is successfully uploaded to S3 (multipart only). */
|
|
47
54
|
onPartUpload?: (file: File, partNumber: number, totalParts: number) => void;
|
|
48
|
-
/**
|
|
49
|
-
* Fires once after `CreateMultipartUpload` succeeds.
|
|
50
|
-
* Only called during multipart uploads.
|
|
51
|
-
* Receives the S3-assigned `uploadId` — useful for server-side tracking.
|
|
52
|
-
*/
|
|
55
|
+
/** Fires once after `CreateMultipartUpload` succeeds (multipart only). */
|
|
53
56
|
onMultipartInit?: (file: File, uploadId: string) => void;
|
|
54
57
|
/** Fires when the upload finishes successfully. */
|
|
55
58
|
onSuccess?: (file: File, result: UploadResult) => Promise<void> | void;
|
|
@@ -58,17 +61,24 @@ export type UploadHooks = {
|
|
|
58
61
|
/** Fires when the upload is cancelled via `cancel()`. */
|
|
59
62
|
onCancel?: (file: File | null) => void;
|
|
60
63
|
};
|
|
64
|
+
/** Retry configuration for failed network requests. */
|
|
61
65
|
export type RetryConfig = {
|
|
62
66
|
/** Maximum number of retry attempts per request. @default 3 */
|
|
63
67
|
maxRetries?: number;
|
|
64
68
|
/** Base delay in ms for exponential backoff. @default 1000 */
|
|
65
69
|
baseDelay?: number;
|
|
66
70
|
};
|
|
71
|
+
/** Upload engine configuration for `useUpload` and `useMultiUpload`. */
|
|
67
72
|
export type UploadConfig = {
|
|
73
|
+
/** Enable multipart uploads for large files. */
|
|
68
74
|
multipart?: boolean;
|
|
75
|
+
/** Allowed file extensions or MIME types. */
|
|
69
76
|
accept?: string[];
|
|
77
|
+
/** Max file size in bytes. */
|
|
70
78
|
maxFileSize?: number;
|
|
79
|
+
/** Max number of files (multi-upload). */
|
|
71
80
|
maxFiles?: number;
|
|
81
|
+
/** File size threshold in bytes above which multipart is used. */
|
|
72
82
|
multipartThreshold?: number;
|
|
73
83
|
/**
|
|
74
84
|
* Multipart part size in bytes. Minimum 5 MB.
|
|
@@ -76,25 +86,18 @@ export type UploadConfig = {
|
|
|
76
86
|
* @default 5 MB
|
|
77
87
|
*/
|
|
78
88
|
partSize?: number;
|
|
89
|
+
/** Number of parts uploaded concurrently (multipart). */
|
|
79
90
|
concurrentParts?: number;
|
|
91
|
+
/** Number of files uploaded concurrently (multi-upload). */
|
|
80
92
|
concurrentFiles?: number;
|
|
81
93
|
/** Retry configuration for failed network requests. */
|
|
82
94
|
retry?: RetryConfig;
|
|
83
95
|
/**
|
|
84
96
|
* Store for resumable multipart uploads.
|
|
85
97
|
*
|
|
86
|
-
* - Omit / `undefined` —
|
|
87
|
-
* - `false` — same as omitting
|
|
88
|
-
* - Custom `UploadStore` — persist `uploadId` across sessions
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* // Enable localStorage-based resumability
|
|
93
|
-
* useUpload({ api, uploadStore: createLocalStorageStore() });
|
|
94
|
-
*
|
|
95
|
-
* // Custom backend
|
|
96
|
-
* useUpload({ api, uploadStore: myDbStore });
|
|
97
|
-
* ```
|
|
98
|
+
* - Omit / `undefined` — abort immediately on cancel or error.
|
|
99
|
+
* - `false` — same as omitting.
|
|
100
|
+
* - Custom `UploadStore` — persist `uploadId` across sessions.
|
|
98
101
|
*/
|
|
99
102
|
uploadStore?: UploadStore | false;
|
|
100
103
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { UploadProgress, UploadRequestOptions, RetryConfig } from "../types";
|
|
2
|
-
import type { S3Api } from "
|
|
2
|
+
import type { S3Api } from "@better-s3/core";
|
|
3
3
|
import type { UploadStore } from "../types/upload-store";
|
|
4
4
|
export declare function uploadMultipart(api: S3Api, file: File, objectKey: string, partSize: number, concurrentParts: number, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal, requestOptions?: UploadRequestOptions, retryConfig?: RetryConfig, uploadStore?: UploadStore | false, onPartUpload?: (partNumber: number, totalParts: number) => void, onMultipartInit?: (uploadId: string, key: string) => void): Promise<string | undefined>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UploadConfig, UploadProgress, UploadResult, UploadRequestOptions } from "../types";
|
|
2
|
-
import type { S3Api } from "
|
|
2
|
+
import type { S3Api } from "@better-s3/core";
|
|
3
3
|
export type UploadEngineCallbacks = {
|
|
4
4
|
onProgress?: (progress: UploadProgress) => void;
|
|
5
5
|
/** Called when the upload transitions between internal phases. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UploadConfig, UploadProgress, UploadResult, UploadRequestOptions } from "../types";
|
|
2
|
-
import type { S3Api } from "
|
|
2
|
+
import type { S3Api } from "@better-s3/core";
|
|
3
3
|
export type FileItemStatus = "pending" | "uploading" | "success" | "error";
|
|
4
4
|
export type FileItem = {
|
|
5
5
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-s3/react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1050.0",
|
|
4
4
|
"description": "React hooks for S3-compatible file uploads, downloads, and deletes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"s3",
|
|
@@ -32,12 +32,15 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@better-s3/core": "3.1050.0"
|
|
37
|
+
},
|
|
35
38
|
"peerDependencies": {
|
|
36
39
|
"react": ">=18"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
|
-
"@types/react": "^19.2.
|
|
40
|
-
"react": "^19.2.
|
|
42
|
+
"@types/react": "^19.2.17",
|
|
43
|
+
"react": "^19.2.7",
|
|
41
44
|
"tsup": "^8.5.1",
|
|
42
45
|
"typescript": "6.0.3"
|
|
43
46
|
},
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds an S3 object key by joining path segments with `/`.
|
|
3
|
-
*
|
|
4
|
-
* Trims leading/trailing slashes from each segment and removes empty ones,
|
|
5
|
-
* so you can safely pass optional parts without worrying about double-slashes.
|
|
6
|
-
*
|
|
7
|
-
* Follows the recommended better-s3 key convention:
|
|
8
|
-
* - Personal mode: `buildObjectKey(userId, `${nanoid()}.${ext}`)` → `"user_123/abc.png"`
|
|
9
|
-
* - Org mode: `buildObjectKey(orgId, userId, `${nanoid()}.${ext}`)` → `"org_1/user_123/abc.png"`
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* buildObjectKey("user_123", "uploads", "photo.png")
|
|
14
|
-
* // → "user_123/uploads/photo.png"
|
|
15
|
-
*
|
|
16
|
-
* buildObjectKey("org_1", "", "user_123", "doc.pdf")
|
|
17
|
-
* // → "org_1/user_123/doc.pdf"
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function buildObjectKey(...parts: string[]): string;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats a byte count into a human-readable string.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* formatFileSize(0) // "0 B"
|
|
7
|
-
* formatFileSize(1500) // "1.5 KB"
|
|
8
|
-
* formatFileSize(1048576) // "1.0 MB"
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export declare function formatFileSize(bytes: number): string;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts the lowercase file extension (without the dot) from a filename.
|
|
3
|
-
*
|
|
4
|
-
* Returns an empty string when the filename has no extension.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* getFileExtension("photo.JPG") // "jpg"
|
|
9
|
-
* getFileExtension("archive.tar.gz") // "gz"
|
|
10
|
-
* getFileExtension("README") // ""
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export declare function getFileExtension(filename: string): string;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts a display filename from a `Content-Disposition` response header.
|
|
3
|
-
*
|
|
4
|
-
* Prefers the RFC 5987 `filename*=UTF-8''…` encoding (full Unicode support)
|
|
5
|
-
* over the plain ASCII `filename="…"` fallback.
|
|
6
|
-
*
|
|
7
|
-
* @param header The raw `Content-Disposition` header value (or `null`).
|
|
8
|
-
* @param fallback Returned when no filename can be extracted.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const name = parseContentDispositionFilename(
|
|
13
|
-
* response.headers.get("content-disposition"),
|
|
14
|
-
* "download",
|
|
15
|
-
* );
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function parseContentDispositionFilename(header: string | null, fallback: string): string;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Truncates a filename while always preserving the file extension.
|
|
3
|
-
* The cut happens before the extension so the extension is always visible.
|
|
4
|
-
*
|
|
5
|
-
* truncateFilename("namenamenamenamename.pdf", 20) → "namenamename… .pdf"
|
|
6
|
-
* truncateFilename("short.pdf", 20) → "short.pdf"
|
|
7
|
-
* truncateFilename(".gitignore", 8) → ".gitigno…"
|
|
8
|
-
*/
|
|
9
|
-
export declare function truncateFilename(name: string, maxChars?: number): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates a `File` against accept-list and size constraints.
|
|
3
|
-
*
|
|
4
|
-
* Returns a human-readable error string when validation fails,
|
|
5
|
-
* or `null` when the file is valid.
|
|
6
|
-
*
|
|
7
|
-
* Mirrors the server-side `validateFile` so you can apply the same
|
|
8
|
-
* rules on the client before initiating an upload.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const error = validateFile(file, {
|
|
13
|
-
* accept: ["image/*", ".pdf"],
|
|
14
|
-
* maxFileSize: 10 * 1024 * 1024, // 10 MB
|
|
15
|
-
* });
|
|
16
|
-
* if (error) toast.error(error);
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare function validateFile(file: File, options: {
|
|
20
|
-
accept?: string[];
|
|
21
|
-
maxFileSize?: number;
|
|
22
|
-
}): string | null;
|
package/dist/types/s3-api.d.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
export type PresignResponse = {
|
|
2
|
-
key: string;
|
|
3
|
-
bucket: string;
|
|
4
|
-
url: string;
|
|
5
|
-
expiresIn: number;
|
|
6
|
-
};
|
|
7
|
-
export type UploadPresignResponse = {
|
|
8
|
-
key: string;
|
|
9
|
-
bucket: string;
|
|
10
|
-
url: string;
|
|
11
|
-
expiresIn: number;
|
|
12
|
-
method: "POST" | "PUT";
|
|
13
|
-
/** Present when `method` is `"POST"`. Must be appended to FormData before the file. */
|
|
14
|
-
fields?: Record<string, string>;
|
|
15
|
-
/** Present when `method` is `"PUT"`. Must be set as request headers on the PUT request. */
|
|
16
|
-
headers?: Record<string, string>;
|
|
17
|
-
};
|
|
18
|
-
/** @deprecated Use {@link UploadPresignResponse} instead. */
|
|
19
|
-
export type PresignedPostResponse = UploadPresignResponse;
|
|
20
|
-
export type MultipartInitResponse = {
|
|
21
|
-
key: string;
|
|
22
|
-
bucket: string;
|
|
23
|
-
uploadId: string;
|
|
24
|
-
};
|
|
25
|
-
export type MultipartPartResponse = {
|
|
26
|
-
presignedUrl: string;
|
|
27
|
-
partNumber: number;
|
|
28
|
-
uploadId: string;
|
|
29
|
-
bucket: string;
|
|
30
|
-
expiresIn: number;
|
|
31
|
-
/** Exact byte size locked into this part's presigned URL signature. */
|
|
32
|
-
partSize?: number;
|
|
33
|
-
};
|
|
34
|
-
export type MultipartListPartsResponse = {
|
|
35
|
-
parts: Array<{
|
|
36
|
-
partNumber: number;
|
|
37
|
-
/** Byte size of the uploaded part. */
|
|
38
|
-
size: number;
|
|
39
|
-
/** ETag of the uploaded part. */
|
|
40
|
-
eTag: string;
|
|
41
|
-
}>;
|
|
42
|
-
};
|
|
43
|
-
export type UploadConfirmResponse = {
|
|
44
|
-
key: string;
|
|
45
|
-
bucket: string;
|
|
46
|
-
contentType?: string;
|
|
47
|
-
contentLength: number;
|
|
48
|
-
eTag?: string;
|
|
49
|
-
/** S3 object metadata (x-amz-meta-*). Always present; empty object when no metadata was stored. */
|
|
50
|
-
metadata: Record<string, string>;
|
|
51
|
-
/** Resolved ACL. Omitted when ACL lookup is disabled or unsupported. */
|
|
52
|
-
acl?: "private" | "public-read";
|
|
53
|
-
/** Display file name parsed from the object's Content-Disposition header. */
|
|
54
|
-
fileName?: string;
|
|
55
|
-
/** Object version ID. Only present when bucket versioning is enabled. */
|
|
56
|
-
versionId?: string;
|
|
57
|
-
/** Last-modified timestamp from HeadObject (ISO 8601 string). */
|
|
58
|
-
lastModified?: string;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Protocol interface for the presign API consumed by `@better-s3/react` hooks.
|
|
62
|
-
*
|
|
63
|
-
* The default implementation is `createS3Api()` from `@better-s3/server`, but
|
|
64
|
-
* any backend that satisfies this interface can be used instead.
|
|
65
|
-
*/
|
|
66
|
-
export type S3Api = {
|
|
67
|
-
upload: (payload: {
|
|
68
|
-
key: string;
|
|
69
|
-
contentType?: string;
|
|
70
|
-
/**
|
|
71
|
-
* Exact byte size of the file. When provided the presigned POST policy
|
|
72
|
-
* locks `content-length-range` to `[fileSize, fileSize]` so S3 rejects
|
|
73
|
-
* uploads of any other size at the storage layer.
|
|
74
|
-
*/
|
|
75
|
-
fileSize?: number;
|
|
76
|
-
metadata?: Record<string, string>;
|
|
77
|
-
bucket?: string;
|
|
78
|
-
acl?: "private" | "public-read";
|
|
79
|
-
/** Original file name. Stored as `Content-Disposition` on the S3 object. */
|
|
80
|
-
fileName?: string;
|
|
81
|
-
}) => Promise<UploadPresignResponse>;
|
|
82
|
-
confirm: (payload: {
|
|
83
|
-
key: string;
|
|
84
|
-
bucket?: string;
|
|
85
|
-
}) => Promise<UploadConfirmResponse>;
|
|
86
|
-
download: (key: string, options?: {
|
|
87
|
-
fileName?: string;
|
|
88
|
-
bucket?: string;
|
|
89
|
-
}) => Promise<PresignResponse>;
|
|
90
|
-
delete: (key: string, options?: {
|
|
91
|
-
bucket?: string;
|
|
92
|
-
}) => Promise<{
|
|
93
|
-
success: boolean;
|
|
94
|
-
bucket: string;
|
|
95
|
-
key: string;
|
|
96
|
-
}>;
|
|
97
|
-
multipart: {
|
|
98
|
-
init: (payload: {
|
|
99
|
-
key: string;
|
|
100
|
-
contentType?: string;
|
|
101
|
-
/** Declared total byte size of the file. */
|
|
102
|
-
fileSize?: number;
|
|
103
|
-
metadata?: Record<string, string>;
|
|
104
|
-
bucket?: string;
|
|
105
|
-
acl?: "private" | "public-read";
|
|
106
|
-
/** Original file name. Stored as `Content-Disposition` on the S3 object. */
|
|
107
|
-
fileName?: string;
|
|
108
|
-
}) => Promise<MultipartInitResponse>;
|
|
109
|
-
signPart: (payload: {
|
|
110
|
-
key: string;
|
|
111
|
-
uploadId: string;
|
|
112
|
-
partNumber: number;
|
|
113
|
-
/**
|
|
114
|
-
* Exact byte size of the part. When provided, Content-Length is included
|
|
115
|
-
* in the HMAC signature so S3 rejects any part body of a different size.
|
|
116
|
-
*/
|
|
117
|
-
partSize?: number;
|
|
118
|
-
bucket?: string;
|
|
119
|
-
}) => Promise<MultipartPartResponse>;
|
|
120
|
-
/**
|
|
121
|
-
* List already-uploaded parts for an in-progress multipart upload.
|
|
122
|
-
* Used by the resumable upload flow to skip already-completed parts.
|
|
123
|
-
*/
|
|
124
|
-
listParts: (payload: {
|
|
125
|
-
key: string;
|
|
126
|
-
uploadId: string;
|
|
127
|
-
bucket?: string;
|
|
128
|
-
}) => Promise<MultipartListPartsResponse>;
|
|
129
|
-
complete: (payload: {
|
|
130
|
-
key: string;
|
|
131
|
-
uploadId: string;
|
|
132
|
-
parts: Array<{
|
|
133
|
-
partNumber: number;
|
|
134
|
-
}>;
|
|
135
|
-
bucket?: string;
|
|
136
|
-
}) => Promise<{
|
|
137
|
-
key: string;
|
|
138
|
-
bucket: string;
|
|
139
|
-
uploadId: string;
|
|
140
|
-
contentLength: number;
|
|
141
|
-
contentType?: string;
|
|
142
|
-
eTag?: string;
|
|
143
|
-
/** S3 object metadata (x-amz-meta-*). Always present; empty object when no metadata was stored. */
|
|
144
|
-
metadata: Record<string, string>;
|
|
145
|
-
/** Object version ID. Only present when bucket versioning is enabled. */
|
|
146
|
-
versionId?: string;
|
|
147
|
-
/** Last-modified timestamp from HeadObject (ISO 8601 string). */
|
|
148
|
-
lastModified?: string;
|
|
149
|
-
}>;
|
|
150
|
-
abort: (payload: {
|
|
151
|
-
key: string;
|
|
152
|
-
uploadId: string;
|
|
153
|
-
bucket?: string;
|
|
154
|
-
}) => Promise<{
|
|
155
|
-
aborted: boolean;
|
|
156
|
-
}>;
|
|
157
|
-
};
|
|
158
|
-
};
|