diff --git a/index.test-d.ts b/index.test-d.ts index 7a9a5d0..28fcd13 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -40,6 +40,8 @@ import { UploadPartCopySourceData, UploadPartCopyOptions, UploadPartCopyResult, + UploadPartOptions, + UploadPartResult, PartInfo, SourceData, IncomingHttpHeaders, @@ -154,6 +156,11 @@ class SimpleClient implements IObjectSimple { return {} as any; } + async uploadPart(name: string, uploadId: string, partNo: number, file: any, start: number, end: number, options?: UploadPartOptions): Promise { + console.log(name, uploadId, partNo, file, start, end, options); + return {} as any; + } + async asyncSignatureUrl(name: string, options?: SignatureUrlOptions): Promise { console.log(name, options); return ''; @@ -476,3 +483,62 @@ const uploadPartCopyResult4 = await simpleClient.uploadPartCopy( partCopySourceData ); expectType(uploadPartCopyResult4.etag); + +// Test uploadPart basic usage +const uploadPartResult1 = await simpleClient.uploadPart( + 'large-file.bin', + 'uploadId123', + 1, + '/path/to/file.bin', + 0, + 1048576 +); +expectType(uploadPartResult1.name); +expectType(uploadPartResult1.etag); +expectType(uploadPartResult1.res.status); + +// Test uploadPart with options +const uploadPartResult2 = await simpleClient.uploadPart( + 'large-file.bin', + 'uploadId123', + 2, + '/path/to/file.bin', + 1048576, + 2097152, + { + timeout: 60000, + disabledMD5: false + } +); +expectType(uploadPartResult2.etag); + +// Test uploadPart with File object (browser environment) +const fileObject = new File(['content'], 'test.txt'); +const uploadPartResult3 = await simpleClient.uploadPart( + 'upload.txt', + 'uploadId456', + 3, + fileObject, + 0, + 100000, + { + headers: { + 'x-oss-server-side-encryption': 'AES256' + }, + mime: 'text/plain' + } +); +expectType(uploadPartResult3.name); +expectType(uploadPartResult3.etag); +expectType(uploadPartResult3.res.status); + +// Test uploadPart with different byte ranges +const uploadPartResult4 = await simpleClient.uploadPart( + 'video.mp4', + 'uploadId789', + 5, + '/path/to/video.mp4', + 5242880, + 10485760 +); +expectType(uploadPartResult4.etag); diff --git a/src/index.ts b/src/index.ts index efecf25..7b30565 100644 --- a/src/index.ts +++ b/src/index.ts @@ -410,6 +410,20 @@ export interface UploadPartCopyResult { res: NormalSuccessResponse; } +export interface UploadPartOptions extends RequestOptions { + headers?: IncomingHttpHeaders; + mime?: string; + /** disable MD5 check */ + disabledMD5?: boolean; +} + +export interface UploadPartResult { + name: string; + /** part etag */ + etag: string; + res: NormalSuccessResponse; +} + export type HTTPMethods = 'GET' | 'POST' | 'DELETE' | 'PUT'; export interface ResponseHeaderType { @@ -557,6 +571,11 @@ export interface IObjectSimple { */ uploadPartCopy(name: string, uploadId: string, partNo: number, range: string, sourceData: UploadPartCopySourceData, options?: UploadPartCopyOptions): Promise; + /** + * Upload a part in a multipart upload transaction. + */ + uploadPart(name: string, uploadId: string, partNo: number, file: string | Buffer | Readable, start: number, end: number, options?: UploadPartOptions): Promise; + /** * Signature a url for the object. * @param name