Skip to content

Commit

Permalink
fix: keep same metas as file stream on file mode (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed May 19, 2019
1 parent 77a3766 commit 72b03aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/middleware/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ module.exports = options => {
encoding: part.encoding,
mime: part.mime,
};
// keep same property name as file stream
// https://github.com/cojs/busboy/blob/master/index.js#L114
meta.fieldname = meta.field;
meta.transferEncoding = meta.encoding;
meta.mimeType = meta.mime;

ctx.coreLogger.debug('[egg-multipart:storeMultipart] handle stream part: %j', meta);
// empty part, ignore it
if (!part.filename) {
Expand Down
3 changes: 3 additions & 0 deletions test/file-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ describe('test/file-mode.test.js', () => {
assert(data.files[0].filepath.startsWith(app.config.multipart.tmpdir));

assert(data.files[1].field === 'file2');
assert(data.files[1].fieldname === 'file2');
assert(data.files[1].filename === 'file-mode.test.js');
assert(data.files[1].encoding === '7bit');
assert(data.files[1].transferEncoding === '7bit');
assert(data.files[1].mime === 'application/javascript');
assert(data.files[1].mimeType === 'application/javascript');
assert(data.files[1].filepath.startsWith(app.config.multipart.tmpdir));

assert(data.files[2].field === 'bigfile');
Expand Down

0 comments on commit 72b03aa

Please sign in to comment.