Egg: [RFC] Provide an easy way to handle file upload

Created on 28 Sep 2018  ·  7Comments  ·  Source: eggjs/egg

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' } ] }
egg-multipart proposals

Most helpful comment

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

All 7 comments

java 好像是这样的。

may provide a config for tmp file cleaning schedule

Tmp file cleaned by developer manually may be better.

egg-multipart never know when files should be dropped.

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

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.

@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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

occultskyrong picture occultskyrong  ·  35Comments

atian25 picture atian25  ·  68Comments

andylei18 picture andylei18  ·  35Comments

killagu picture killagu  ·  48Comments

itsky365 picture itsky365  ·  62Comments