richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 259 forks source link

req.files.sampleFile is undefined #344

Closed hypo-thesis closed 1 year ago

hypo-thesis commented 1 year ago

I am using the sample from the docs. I am on node 19.0.1 and I get

req.files [Object: null prototype] {
  fileUpload: {
    name: 'sampleFile.mp3',
    data: <Buffer 49 44 33 04 00 00 00 00 00 23 54 53 53 45 00 00 00 0f 00 00 03 4c 61 76 66 35 37 2e 38 33 2e 31 30 30 00 00 00 00 00 00 00 00 00 00 00 ff fb 50 00 00 ... 52029 more bytes>,
    size: 52079,
    encoding: '7bit',
    tempFilePath: '',
    truncated: false,
    mimetype: 'audio/mpeg',
    md5: '4f774d08f0c3e66594704d6be4a2d052',
    mv: [Function: mv]
  }
}

as my req.files and yet req.files.sampleFile is coming back as undefined. I cannot write it on the hdd and no error is coming back. What should I do?

Caresle commented 1 year ago

Hi, I think you need to call req.files.fileUpload instead of req.files.sampleFile this because maybe the name of the input(file) is "fileUpload" and not "sampleFile".

Here is the example what I get when calling console.log(req.files)

[Object: null prototype] {
  sampleFile: {
    name: '12in23.txt',
    data: <Buffer 31 32 20 64 69 66 66 65 72 65 6e 74 20 70 72 6f 67 72 61 6d 6d 69 6e 67 20 6c 61 6e 67 75 61 67 65 73 20 69 6e 20 32 30 32 33 2e 0d 0a 0d 0a 31 2e 20 ... 104 more bytes>,
    size: 154,
    encoding: '7bit',
    tempFilePath: '',
    truncated: false,
    mimetype: 'text/plain',
    md5: 'fb00791bb6bd75b9c88826ac963e2b7f',
    mv: [Function: mv]
  }
}