Skip to content

Commit 666d9f6

Browse files
killaguclaude
andauthored
feat: add uploadPart method type definition (#12)
Add uploadPart method for uploading a part in a multipart upload transaction: - UploadPartOptions interface with headers, mime, and disabledMD5 fields - UploadPartResult interface with name, etag, and res fields - Method signature supporting file path or File object with byte range (start, end) - Comprehensive type tests covering various usage scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added ability to upload individual file parts as part of multipart uploads. * Configurable upload options: custom headers, MIME type, and optional MD5 checksum control. * Part upload now returns result details (including part identifier/etag and server response) for resumable or multipart workflows. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent cd9829a commit 666d9f6

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

index.test-d.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
UploadPartCopySourceData,
4141
UploadPartCopyOptions,
4242
UploadPartCopyResult,
43+
UploadPartOptions,
44+
UploadPartResult,
4345
PartInfo,
4446
SourceData,
4547
IncomingHttpHeaders,
@@ -154,6 +156,11 @@ class SimpleClient implements IObjectSimple {
154156
return {} as any;
155157
}
156158

159+
async uploadPart(name: string, uploadId: string, partNo: number, file: any, start: number, end: number, options?: UploadPartOptions): Promise<UploadPartResult> {
160+
console.log(name, uploadId, partNo, file, start, end, options);
161+
return {} as any;
162+
}
163+
157164
async asyncSignatureUrl(name: string, options?: SignatureUrlOptions): Promise<string> {
158165
console.log(name, options);
159166
return '';
@@ -476,3 +483,62 @@ const uploadPartCopyResult4 = await simpleClient.uploadPartCopy(
476483
partCopySourceData
477484
);
478485
expectType<string>(uploadPartCopyResult4.etag);
486+
487+
// Test uploadPart basic usage
488+
const uploadPartResult1 = await simpleClient.uploadPart(
489+
'large-file.bin',
490+
'uploadId123',
491+
1,
492+
'/path/to/file.bin',
493+
0,
494+
1048576
495+
);
496+
expectType<string>(uploadPartResult1.name);
497+
expectType<string>(uploadPartResult1.etag);
498+
expectType<number>(uploadPartResult1.res.status);
499+
500+
// Test uploadPart with options
501+
const uploadPartResult2 = await simpleClient.uploadPart(
502+
'large-file.bin',
503+
'uploadId123',
504+
2,
505+
'/path/to/file.bin',
506+
1048576,
507+
2097152,
508+
{
509+
timeout: 60000,
510+
disabledMD5: false
511+
}
512+
);
513+
expectType<string>(uploadPartResult2.etag);
514+
515+
// Test uploadPart with File object (browser environment)
516+
const fileObject = new File(['content'], 'test.txt');
517+
const uploadPartResult3 = await simpleClient.uploadPart(
518+
'upload.txt',
519+
'uploadId456',
520+
3,
521+
fileObject,
522+
0,
523+
100000,
524+
{
525+
headers: {
526+
'x-oss-server-side-encryption': 'AES256'
527+
},
528+
mime: 'text/plain'
529+
}
530+
);
531+
expectType<string>(uploadPartResult3.name);
532+
expectType<string>(uploadPartResult3.etag);
533+
expectType<number>(uploadPartResult3.res.status);
534+
535+
// Test uploadPart with different byte ranges
536+
const uploadPartResult4 = await simpleClient.uploadPart(
537+
'video.mp4',
538+
'uploadId789',
539+
5,
540+
'/path/to/video.mp4',
541+
5242880,
542+
10485760
543+
);
544+
expectType<string>(uploadPartResult4.etag);

src/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ export interface UploadPartCopyResult {
410410
res: NormalSuccessResponse;
411411
}
412412

413+
export interface UploadPartOptions extends RequestOptions {
414+
headers?: IncomingHttpHeaders;
415+
mime?: string;
416+
/** disable MD5 check */
417+
disabledMD5?: boolean;
418+
}
419+
420+
export interface UploadPartResult {
421+
name: string;
422+
/** part etag */
423+
etag: string;
424+
res: NormalSuccessResponse;
425+
}
426+
413427
export type HTTPMethods = 'GET' | 'POST' | 'DELETE' | 'PUT';
414428

415429
export interface ResponseHeaderType {
@@ -557,6 +571,11 @@ export interface IObjectSimple {
557571
*/
558572
uploadPartCopy(name: string, uploadId: string, partNo: number, range: string, sourceData: UploadPartCopySourceData, options?: UploadPartCopyOptions): Promise<UploadPartCopyResult>;
559573

574+
/**
575+
* Upload a part in a multipart upload transaction.
576+
*/
577+
uploadPart(name: string, uploadId: string, partNo: number, file: string | Buffer | Readable, start: number, end: number, options?: UploadPartOptions): Promise<UploadPartResult>;
578+
560579
/**
561580
* Signature a url for the object.
562581
* @param name

0 commit comments

Comments
 (0)