Skip to content

Commit 8b77050

Browse files
committed
Replace File with FileLike
1 parent 9eb2662 commit 8b77050

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-chunk-upload-action",
3-
"version": "7.1.0",
3+
"version": "8.0.0",
44
"description": "Uploading large files with chunking using server action in Next.js",
55
"main": "dist/index.js",
66
"scripts": {
@@ -52,4 +52,4 @@
5252
"typescript",
5353
"ts"
5454
]
55-
}
55+
}

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
* [API Reference]: https://github.com/a179346/nextjs-chunk-upload-action/blob/main/docs/api-reference.md
99
*/
1010

11+
export interface FileLike {
12+
readonly size: number;
13+
slice(start?: number, end?: number, contentType?: string): Blob;
14+
}
15+
1116
export type Primitive = string | boolean | number | undefined | null;
1217

1318
export type Metadata = Record<string, Primitive>;
@@ -27,7 +32,7 @@ export type ChunkUploadHandler<TMetadata extends Metadata = Metadata> = (
2732
) => Promise<void>;
2833

2934
export interface ChunkUploaderOptions<TMetadata extends Metadata> {
30-
file: File;
35+
file: FileLike;
3136
/**
3237
* The function that defines how the chunk is uploaded to the server.
3338
*/
@@ -200,7 +205,7 @@ export class ChunkUploader<TMetadata extends Metadata> {
200205
protected _position: number;
201206
protected _error?: unknown;
202207

203-
protected readonly _file: File;
208+
protected readonly _file: FileLike;
204209
protected readonly _onChunkUpload: ChunkUploadHandler<TMetadata>;
205210
protected readonly _chunkBytes: number;
206211
protected readonly _metadata: Readonly<TMetadata>;
@@ -271,7 +276,6 @@ export class ChunkUploader<TMetadata extends Metadata> {
271276

272277
protected _validateOptions(options: ChunkUploaderOptions<TMetadata>) {
273278
if (!options.file) throw new Error('File is required');
274-
if (!(options.file instanceof File)) throw new Error('File must be an instance of File');
275279

276280
if (typeof options.onChunkUpload !== 'function')
277281
throw new Error('onChunkUpload must be a function');

0 commit comments

Comments
 (0)