简体   繁体   中英

Get full path of file in node.js with module express-busboy

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(eg 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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM