3

I'm using multer to upload images with express and node from a form, however all the files names come out like "8f92a1388f70c6c88eb32489f6bcfcc9". There isn't even an extension attached. How to I display this on the client side?

1
  • Did you find the solution to this issue? Commented Mar 29, 2018 at 5:44

1 Answer 1

4

try:

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, '/where/ever/the/upload/dir/is')
  },
  filename: function (req, file, cb) {
    cb(null, file.orignalname)
  }
})

var upload = multer({ storage: storage })

Instead of:

var upload = multer({ dest: 'uploads/' })

Requesting the file:
With the proper permissions set on the file/or directory your server should be able to request it fine, remember to explicitly write the file name with an extension if you aren't doing anything fancy after the file is written ;)

If you want more control over your uploads, you'll want to use the storage option instead of dest. Multer ships with storage engines DiskStorage and MemoryStorage; More engines are available from third parties. --The Horse
(ref: github: expressjs/multer)

Note: Multer will not append any file extension for you, your function should return a filename complete with an file extension

Sign up to request clarification or add additional context in comments.

3 Comments

Then what does replace upload.single('field')?
NOTE: There is a typo in the given property name - file.orignalname should be file.originalname
@armadadrive agreed.. the edit queue is full so my change can't go in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.