@@ -5,7 +5,6 @@ const SparkMD5 = require('spark-md5');
5
5
const chalk = require ( 'chalk' ) ;
6
6
const prompts = require ( 'prompts' ) ;
7
7
const path = require ( 'path' ) ;
8
- const FormData = require ( 'form-data' ) ;
9
8
require ( 'winston-daily-rotate-file' ) ;
10
9
const logger = require ( '../lib/log' ) ;
11
10
const ProgressBar = require ( 'progress' ) ;
@@ -29,26 +28,24 @@ process.on('uncaughtException', error => {
29
28
const upload = async ( filePath , parts = [ ] ) => {
30
29
const totalChunk = Math . ceil ( fileSize / CHUNK_SIZE ) ;
31
30
32
- const bar = new ProgressBar ( ':bar [:current/:total] :percent' , { total : totalChunk } ) ;
31
+ const bar = new ProgressBar ( ':bar [:current/:total] :percent ' , { total : totalChunk } ) ;
33
32
const uploadChunk = async ( currentChunk , currentChunkIndex , parts , isRetry ) => {
34
33
if ( parts . some ( ( { partNumber, size } ) => partNumber === currentChunkIndex && size === currentChunk . length ) ) {
35
34
bar . tick ( ) ;
36
35
return Promise . resolve ( ) ;
37
36
}
38
37
39
- const form = new FormData ( ) ;
40
- form . append ( 'chunk' , currentChunk , {
41
- filename : requestUrl . replace ( / ^ h t t p ( s ) ? : \/ \/ .+ ?\/ .+ ?\/ .+ ?\/ / , '' )
42
- } ) ;
43
38
try {
44
39
await _uploadChunk ( requestUrl , {
45
40
uploadId,
46
41
version,
47
42
partNumber : currentChunkIndex ,
48
43
size : currentChunk . length ,
49
- form
44
+ currentChunk
50
45
} , {
51
- headers : form . getHeaders ( ) ,
46
+ headers : {
47
+ 'Content-Type' : 'application/octet-stream'
48
+ } ,
52
49
Authorization
53
50
} ) ;
54
51
bar . tick ( ) ;
@@ -163,7 +160,7 @@ const getFileMD5 = async (filePath) => {
163
160
console . log ( `\n开始计算 MD5\n` )
164
161
logger . info ( '开始计算 MD5' )
165
162
166
- const bar = new ProgressBar ( ':bar [:current/:total] :percent' , { total : totalChunk } ) ;
163
+ const bar = new ProgressBar ( ':bar [:current/:total] :percent ' , { total : totalChunk } ) ;
167
164
await new Promise ( resolve => {
168
165
stream = fs . createReadStream ( filePath , { highWaterMark : CHUNK_SIZE } )
169
166
stream . on ( 'data' , chunk => {
0 commit comments