Skip to content

Conversation

@herudi
Copy link

@herudi herudi commented May 27, 2021

Hi @jkyberneees @schamberg97, i'm try upload file but hang on second request. I've changed and fixed a few lines of code. please correct it again.

This example upload

const multer = require('multer');
const { router, server } = require('0http')({
    server: require('../src/server')()
});

const upload = multer({ 
    storage: multer.diskStorage({
        destination: __dirname,
        filename: (req, file, cb) => cb(null, file.originalname)
    })
});

// try in second request will hang
router.post('/upload', upload.single('file'), (req, res) => {
    if (!req.file) {
        res.statusCode = 400;
        res.end('Failed to upload');
    }
    res.end('Success upload ' + req.file.originalname);
})

server.listen(3000, () => { })

@schamberg97
Copy link
Collaborator

From what I understood with this commit, it partially alleviates the issue. I have tried it with both previous 2.0 version and the new 3.0 (after solving conflicts, obviously). It does fix the issue of hanging, but does not resolve the failure to upload file. It appears that for some reason the route in your demo triggers twice oO

@schamberg97
Copy link
Collaborator

schamberg97 commented May 27, 2021

Adding this check right before const chunk or let chunk declaration also helps to avoid the crash:

if (!bytes.byteLength) {
          if (!isLast) return
          return handler(reqWrapper, resWrapper)
}

However, neither way helps to implement multipart/form-data file upload. Something is probably broken with HttpRequest class

@herudi
Copy link
Author

herudi commented May 27, 2021

at first I saw this error... this.slice is not define or not function.

before

_read (size) {
    return this.slice(0, size)
 }

@schamberg97
Copy link
Collaborator

schamberg97 commented May 27, 2021

I propose we fix these issues together in #14 , because they are made against the newer code base. If you agree, we can close this thread

@herudi
Copy link
Author

herudi commented May 27, 2021

i agree. +1

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants