@midwayjs/upload 3.3.11 → 3.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -70,5 +70,7 @@ export const upload = {
70
70
  tmpdir: join(tmpdir(), 'midway-upload-files'),
71
71
  // cleanTimeout: number,上传的文件在临时目录中多久之后自动删除,默认为 5 分钟
72
72
  cleanTimeout: 5 * 60 * 1000,
73
+ // base64: boolean,设置原始body是否是base64格式,默认为false,一般用于腾讯云的兼容
74
+ base64: false,
73
75
  }
74
76
  ```
@@ -10,5 +10,6 @@ exports.upload = {
10
10
  whitelist: constants_1.uploadWhiteList,
11
11
  tmpdir: (0, path_1.join)((0, os_1.tmpdir)(), 'midway-upload-files'),
12
12
  cleanTimeout: 5 * 60 * 1000,
13
+ base64: false,
13
14
  };
14
15
  //# sourceMappingURL=config.default.js.map
@@ -7,6 +7,7 @@ export interface UploadOptions {
7
7
  whitelist?: string[];
8
8
  tmpdir?: string;
9
9
  cleanTimeout?: number;
10
+ base64?: boolean;
10
11
  }
11
12
  export interface UploadFileInfo<T> {
12
13
  filename: string;
@@ -34,6 +34,7 @@ let UploadMiddleware = class UploadMiddleware {
34
34
  }
35
35
  }
36
36
  async execUpload(ctx, req, res, next, isExpress) {
37
+ var _a;
37
38
  const { mode, tmpdir, fileSize } = this.upload;
38
39
  const boundary = this.getUploadBoundary(req);
39
40
  if (!boundary) {
@@ -76,10 +77,15 @@ let UploadMiddleware = class UploadMiddleware {
76
77
  limit: fileSize,
77
78
  });
78
79
  }
80
+ else if (((_a = req === null || req === void 0 ? void 0 : req.originEvent) === null || _a === void 0 ? void 0 : _a.body) &&
81
+ (typeof req.originEvent.body === 'string' ||
82
+ Buffer.isBuffer(req.originEvent.body))) {
83
+ body = req.originEvent.body;
84
+ }
79
85
  else {
80
86
  body = req.body;
81
87
  }
82
- const data = await (0, parse_1.parseMultipart)(body, boundary);
88
+ const data = await (0, parse_1.parseMultipart)(body, boundary, this.upload);
83
89
  if (!data) {
84
90
  return next();
85
91
  }
package/dist/parse.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from 'stream';
3
- import { UploadFileInfo } from './interface';
4
- export declare const parseMultipart: (body: any, boundary: string) => Promise<{
3
+ import { UploadFileInfo, UploadOptions } from './interface';
4
+ export declare const parseMultipart: (body: any, boundary: string, uploadConfig: UploadOptions) => Promise<{
5
5
  files: any[];
6
6
  fields: {};
7
7
  }>;
package/dist/parse.js CHANGED
@@ -3,9 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseHead = exports.bufferSplit = exports.bufferIndexOf = exports.parseFromReadableStream = exports.parseMultipart = void 0;
4
4
  const stream_1 = require("stream");
5
5
  const headSeparator = Buffer.from('\r\n\r\n');
6
- const parseMultipart = async (body, boundary) => {
6
+ const parseMultipart = async (body, boundary, uploadConfig) => {
7
7
  if (typeof body === 'string') {
8
- body = Buffer.from(body);
8
+ if (uploadConfig.base64) {
9
+ body = Buffer.from(body, 'base64');
10
+ }
11
+ else {
12
+ body = Buffer.from(body);
13
+ }
9
14
  }
10
15
  const bufferSeparator = Buffer.from('\r\n--' + boundary);
11
16
  const fields = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/upload",
3
- "version": "3.3.11",
3
+ "version": "3.4.0-beta.2",
4
4
  "description": "Midway Component for upload",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -25,14 +25,14 @@
25
25
  "raw-body": "2.5.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@midwayjs/core": "^3.3.5",
29
- "@midwayjs/decorator": "^3.3.4",
30
- "@midwayjs/express": "^3.3.11",
31
- "@midwayjs/faas": "^3.3.5",
32
- "@midwayjs/koa": "^3.3.6",
33
- "@midwayjs/mock": "^3.3.5",
34
- "@midwayjs/serverless-app": "^3.3.9",
35
- "@midwayjs/web": "^3.3.9"
28
+ "@midwayjs/core": "^3.4.0-beta.2",
29
+ "@midwayjs/decorator": "^3.4.0-beta.2",
30
+ "@midwayjs/express": "^3.4.0-beta.2",
31
+ "@midwayjs/faas": "^3.4.0-beta.2",
32
+ "@midwayjs/koa": "^3.4.0-beta.2",
33
+ "@midwayjs/mock": "^3.4.0-beta.2",
34
+ "@midwayjs/serverless-app": "^3.4.0-beta.2",
35
+ "@midwayjs/web": "^3.4.0-beta.2"
36
36
  },
37
- "gitHead": "18610c9dd1cd329b83a81e4053eb01b9b2b2e8e2"
37
+ "gitHead": "a61721d3946b30fd4cac183265edcd99b31ac72b"
38
38
  }