koa-body file upload async

时间:2016-07-11 21:05:26

标签: javascript koa

I'm having some issues with cut off files. Can someone please confirm, is this going to complete the upload before returning my response? What can be done to fix it?

const router = require('koa-router')(),
    koaBody = require('koa-body')({
        multipart: true,
        formLimit: 2000 * 1024,
        formidable: {
            uploadDir,
        },
    })

router.post('/uploadImage', koaBody, function *() {
    const {fields, files} = this.request.body
    const f = files['files[]']
    const {username} = fields

    // console.log('uploadImage', username, f.path, f.name)

    if(res.status !== 200) {
        this.status = res.status
        this.statusText = res.statusText
        return
    }
    const {ipfspath} = yield res.json()
    const url = 'https://example.com' + ipfspath
    this.body = {files: [{url}]}
})
export default router.routes()

0 个答案:

没有答案