Skip to content

Commit 81b4993

Browse files
author
pedro
committed
fix:修复文件上传的环境bug
1 parent 81c0a18 commit 81b4993

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

lib/extend.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export const multipart = (app: Application) => {
151151
}
152152
// otherwise, it's a stream
153153
// part.fieldname, part.filename, part.encoding, part.mime
154+
// _readableState.length
154155
// part.readableLength 31492 检查单个文件的大小
155156
// 超过长度,报错
156157
// 检查extension,报错
@@ -161,7 +162,7 @@ export const multipart = (app: Application) => {
161162
throw new FileExtensionException({ msg: `不支持类型为${ext}的文件` });
162163
}
163164
const { valid, conf } = checkSingleFileSize(
164-
part.readableLength,
165+
part._readableState.length,
165166
opts && opts.singleLimit
166167
);
167168
if (!valid) {
@@ -170,7 +171,7 @@ export const multipart = (app: Application) => {
170171
});
171172
}
172173
// 计算总大小
173-
totalSize += part.readableLength;
174+
totalSize += part._readableState.length;
174175
const tmp = cloneDeep(part);
175176
files.push(tmp);
176177
// 恢复再次接受data

lib/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class Uploader {
8080
* 生成图片的md5
8181
*/
8282
public generateMd5(data: any) {
83-
const buf = data.readableBuffer._getBuffer(data.readableLength);
83+
const buf = data._readableState.buffer.head.data;
8484
const md5 = crypto.createHash('md5');
8585
return md5.update(buf).digest('hex');
8686
}

0 commit comments

Comments
 (0)