@@ -64,6 +64,9 @@ class InitPartUploadTask implements Task {
6464 const filenameResult = await this . file . name ( )
6565 if ( ! isSuccessResult ( filenameResult ) ) return filenameResult
6666
67+ const fileKeyResult = await this . file . key ( )
68+ if ( ! isSuccessResult ( fileKeyResult ) ) return fileKeyResult
69+
6770 // 首先检查 context 上的 upload id 有没有过期
6871 if ( this . context . uploadPartId ) {
6972 const nowTime = Date . now ( ) / 1e3
@@ -75,9 +78,9 @@ class InitPartUploadTask implements Task {
7578 abort : this . abort ,
7679 token : this . context ! . token ! ,
7780 bucket : this . context . token ! . bucket ,
78- key : filenameResult . result || undefined ,
7981 uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
8082 uploadId : this . context . uploadPartId . uploadId ,
83+ key : fileKeyResult . result || filenameResult . result || undefined ,
8184 onProgress : progress => { this . updateProgress ( progress . percent , notify ) }
8285 } )
8386
@@ -105,8 +108,8 @@ class InitPartUploadTask implements Task {
105108 abort : this . abort ,
106109 token : this . context ! . token ! ,
107110 bucket : this . context ! . token ! . bucket ,
108- key : filenameResult . result || undefined ,
109111 uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
112+ key : fileKeyResult . result || filenameResult . result || undefined ,
110113 onProgress : progress => { this . updateProgress ( progress . percent , notify ) }
111114 } )
112115
@@ -168,6 +171,9 @@ class UploadPartTask implements Task {
168171 const filenameResult = await this . file . name ( )
169172 if ( ! isSuccessResult ( filenameResult ) ) return filenameResult
170173
174+ const fileKeyResult = await this . file . key ( )
175+ if ( ! isSuccessResult ( fileKeyResult ) ) return fileKeyResult
176+
171177 const fileSizeResult = await this . file . size ( )
172178 if ( ! isSuccessResult ( fileSizeResult ) ) return fileSizeResult
173179
@@ -178,9 +184,9 @@ class UploadPartTask implements Task {
178184 partIndex : this . index ,
179185 token : this . context ! . token ! ,
180186 bucket : this . context ! . token ! . bucket ,
181- key : filenameResult . result || undefined ,
182187 uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
183188 uploadId : this . context ! . uploadPartId ! . uploadId ! ,
189+ key : fileKeyResult . result || filenameResult . result || undefined ,
184190 onProgress : progress => { this . updateProgress ( false , fileSizeResult . result , progress . percent , notify ) }
185191 } )
186192
@@ -233,6 +239,10 @@ class CompletePartUploadTask implements Task {
233239
234240 async process ( notify : ( ) => void ) : Promise < Result > {
235241 this . updateProgress ( 0 , notify )
242+
243+ const fileKeyResult = await this . file . key ( )
244+ if ( ! isSuccessResult ( fileKeyResult ) ) return fileKeyResult
245+
236246 const filenameResult = await this . file . name ( )
237247 if ( ! isSuccessResult ( filenameResult ) ) return filenameResult
238248
@@ -253,10 +263,10 @@ class CompletePartUploadTask implements Task {
253263 customVars : this . vars ,
254264 token : this . context ! . token ! ,
255265 metadata : metadataResult . result ,
256- key : filenameResult . result || undefined ,
257266 uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
258267 mimeType : mimeTypeResult . result || undefined ,
259268 uploadId : this . context ! . uploadPartId ! . uploadId ! ,
269+ key : fileKeyResult . result || filenameResult . result || undefined ,
260270 fileName : filenameResult . result || generateRandomString ( ) , // 和直传行为保持一致
261271 onProgress : progress => { this . updateProgress ( progress . percent , notify ) }
262272 } )
0 commit comments