0

I am using node.js and express-busboy to upload a file from a file input form to the server. The uploaded file will have a path of something like root/useruploaded/formattached/somerandomid(e.g. 9w470066-68b4-549e-9607-1987c72768ac)/myFileInputName/uploaded.file

My express-busboy settings look like this:

bb.extend(app, {
  upload: true,
  path: path.join(__dirname, '/useruploaded/formattached'),
  allowedPath: /^\/contact$/ // <-- My POST
});

Then when I access the file by doing req.files.contactFileUpload.filename I can successfully get the name of the uploaded file.

However, when I go to attach this file to my email, I need the path, which I can't figure out how to get because of the random id folder that busboy puts the user uploaded content into. Otherwise I would be able to do something like

path = path.join(__dirname, '/useruploaded/formattached', req.files.contactFileUpload.filename);

To get the path.

My question is how can I

Stop busboy from putting my files in a random id folder?

OR

Get the full path of the file?

I have tried to do req.files.contactFileUpload.path, but this returns undefined.

Thank you in advance!

Zagonine
  • 2,213
  • 3
  • 22
  • 29
sdr981
  • 405
  • 4
  • 15
  • Did you try to get the property `file` on your object ? https://github.com/yahoo/express-busboy/blob/e49e3b48f3e4c005c017589b9111ef2ab6b60d65/index.js#L123 like this `req.files.contactFileUpload.file` – Zagonine Aug 22 '17 at 18:41
  • @Zagonine If I understand what you're saying - req.files.contactFileUpload.file.path also returns undefined – sdr981 Aug 22 '17 at 18:46
  • No just do : `req.files.contactFileUpload.file` – Zagonine Aug 22 '17 at 18:48
  • @Zagonine Thanks, that worked. If you would like to post that as an answer I will mark it as accepted. – sdr981 Aug 22 '17 at 18:55
  • 1
    Thanks! JFYI: I don't know if you know the module `multer`, but I think it is better than `express-busboy` ;-) – Zagonine Aug 22 '17 at 19:01

1 Answers1

1

You can simply access the uploaded file path at the property file of the returned object.

In your case, in order to get the filepath, you have to do :

req.files.contactFileUpload.file
Zagonine
  • 2,213
  • 3
  • 22
  • 29