multer saving to var folder; not listening to storage options
See original GitHub issueI would like it to save in the uploads directory but it keeps saving to /var/ .
Here is the console output showing the path that it chooses followed by my code snippets.
{ host: 'localhost:3000', connection: 'keep-alive', 'content-length': '1140', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', 'cache-control': 'no-cache', origin: 'chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop', 'postman-token': '15334565-30f7-aeb8-116b-e697e2ab5ff3', 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryLBmxiB0pFtgnhG4u', accept: '*/*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'en-US,en;q=0.9' } STARTING UPLOAD { fieldName: 'image', originalFilename: 'compilers.asm', path: '/var/folders/bt/x2tr818x1wxgybgc8z11h4080000gp/T/1615-1cloh49.w3pexez5mi.asm', headers: { 'content-disposition': 'form-data; name="image"; filename="compilers.asm"', 'content-type': 'application/octet-stream' }, ws: WriteStream { _writableState: WritableState { objectMode: false, highWaterMark: 16384, needDrain: false, ending: true, ended: true, finished: true, decodeStrings: true, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: true, errorEmitted: false, bufferedRequestCount: 0, corkedRequestsFree: [Object] }, writable: false, domain: null, _events: { error: [Function], close: [Function] }, _eventsCount: 2, _maxListeners: undefined, path: '/var/folders/bt/x2tr818x1wxgybgc8z11h4080000gp/T/1615-1cloh49.w3pexez5mi.asm', fd: null, flags: 'w', mode: 438, start: undefined, autoClose: true, pos: undefined, bytesWritten: 938, closed: true }, size: 938, name: 'compilers.asm', type: 'application/octet-stream' }
`var path = require(‘path’) var multer = require(‘multer’) var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, path.join(__dirname + ‘/uploads/’)) }, filename: function (req, file, cb) { cb(null, file.fieldname + ‘-’ + Date.now()) } })
//specify name of file multer should look for //app.post(‘/images’, upload.single(‘image’), images.create)
// var cpUpload = upload.fields([{ name: ‘image’, maxCount: 1 }, { name: ‘resume’, maxCount: 1 }]) // app.post(‘/inputs’, cpUpload, inputs.create)
var upload = multer({storage:storage}).single(‘image’)
exports.create = (req, resp) => { console.log(req.headers) console.log(‘STARTING UPLOAD’) upload(req, resp, err => { if (err) { console.log(‘error=’ + err) } console.log(req.files[‘image’]) resp.json({ success: true, message: ‘image uploaded’ }) })
}`
In Express, I am also using a public folder to serve up the app.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top GitHub Comments
@zhughes3 @s00500 I was able to recreate the problem. Made minor changes, now it is working fine.
Having kind of the same problem on macOS, node 10.10