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

[RFC] Provide an easy way to handle file upload #3052

Closed
fengmk2 opened this issue Sep 28, 2018 · 7 comments · Fixed by eggjs/egg-multipart#19
Closed

[RFC] Provide an easy way to handle file upload #3052

fengmk2 opened this issue Sep 28, 2018 · 7 comments · Fixed by eggjs/egg-multipart#19

Comments

@fengmk2
Copy link
Member

fengmk2 commented Sep 28, 2018

Current State

The default streaming style handle file upload is hard for beginner, they need to know about HTTP in-depth and know how Node.js Stream work.

So we can provide a non streaming style to handle file upload by using server disk.

API demos

// all form fields expect "file" type
const body = ctx.request.body;

// all file paths at server disk.
const files = ctx.request.files;

{ body: { foo: 'fengmk2', love: 'egg', work: 'with Node.js' },
  files:
   [ { field: 'file1',
       filename: 'foooooooo.js',
       encoding: '7bit',
       mime: 'application/javascript',
       truncated: false,
       filepath:
        '/var/folders/7b/drlvfq_x0d54tggx_m2xt27r0000gn/T/egg-multipart-tmp/2018/09/28/17/f9f1193a-5e8a-488d-9539-3c7e7fb0d2b0' },
     { field: 'file2',
       filename: 'file-mode.test.js',
       encoding: '7bit',
       mime: 'application/javascript',
       truncated: false,
       filepath:
        '/var/folders/7b/drlvfq_x0d54tggx_m2xt27r0000gn/T/egg-multipart-tmp/2018/09/28/17/aa4bdee8-e684-4ff7-b1d3-1b5b64754548' },
     { field: 'bigfile',
       filename: 'bigfile.js',
       encoding: '7bit',
       mime: 'application/javascript',
       truncated: false,
       filepath:
        '/var/folders/7b/drlvfq_x0d54tggx_m2xt27r0000gn/T/egg-multipart-tmp/2018/09/28/17/874d3a1d-eb21-4dc4-be32-6891afe46215' } ] }
@popomore
Copy link
Member

java 好像是这样的。

@atian25
Copy link
Member

atian25 commented Sep 28, 2018

may provide a config for tmp file cleaning schedule

@killagu
Copy link
Contributor

killagu commented Sep 28, 2018

Tmp file cleaned by developer manually may be better.

@killagu
Copy link
Contributor

killagu commented Sep 28, 2018

egg-multipart never know when files should be dropped.

@atian25
Copy link
Member

atian25 commented Sep 28, 2018

I means provide a config to developer, such as clean all upload tmp files before 3 days every night

fengmk2 added a commit to eggjs/egg-multipart that referenced this issue Sep 28, 2018
fengmk2 added a commit to eggjs/egg-multipart that referenced this issue Sep 28, 2018
fengmk2 added a commit to eggjs/egg-multipart that referenced this issue Sep 29, 2018
@shiny
Copy link
Contributor

shiny commented Oct 27, 2018

I was confused that my code did not works same as the document described.
Finally I found my egg version is 2.2.1 which fall behind to the change.

@atian25
Copy link
Member

atian25 commented Oct 27, 2018

@shiny try to upgrade the deps ASAP, recommended to use ^.

then retry after reinstall dependencies and please never lock it.

$ # reinstall deps and never lock it.
$ rm -rf node_modules yarn.lock package-lock.json
$ npm i --no-package-lock

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

Successfully merging a pull request may close this issue.

5 participants