Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: getFileStream() can accept non file request #17

Merged
merged 2 commits into from
Aug 7, 2018

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Aug 3, 2018

const stream = await ctx.getFileStream({ required: false });
if (stream.filename) {
  console.log('uploaded ' + stream.filename);
} else {
  console.log('file not exists');
}

closes eggjs/egg#2178

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

```js
const stream = await ctx.getFileStream({ required: false });
if (stream.filename) {
  console.log('uploaded ' + stream.filename);
} else {
  console.log('file not exists');
}
```

closes eggjs/egg#2178
@@ -28,15 +35,25 @@ module.exports = {
* console.log(stream.fields);
* ```
* @method Context#getFileStream
* @param {Object} options
* - {Boolean} options.required - required file submit, default is true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requireFile ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link

codecov bot commented Aug 3, 2018

Codecov Report

Merging #17 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #17   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           3      3           
  Lines          50     56    +6     
=====================================
+ Hits           50     56    +6
Impacted Files Coverage Δ
app/extend/context.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a6656c...00df595. Read the comment docs.

async uploadNotRequiredFile() {
const ctx = this.ctx;
// file not required
const stream = await ctx.getFileStream({ requireFile: false });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@fengmk2 fengmk2 merged commit 5ece18a into master Aug 7, 2018
@fengmk2 fengmk2 deleted the allow-file-not-exists branch August 7, 2018 06:17
@fengmk2
Copy link
Member Author

fengmk2 commented Aug 7, 2018

2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

关于form表单提交file的问题
3 participants