Help with file metadata

I am having problem with the file metadata project. Here is the html I am using

<form action="/upload" method="POST">
		<input type="file" name="file">
		<input type="submit">
</form>

and the nodejs code

var express = require('express');
var multer = require('multer');
var path = require('path');
var upload = multer({ dest: 'uploads/' })

var app = express()

app.use(express.static(path.join(__dirname,'public')))

// app.get('/', function(req, res){

// })

app.post('/upload', upload.single('file'),function(req, res){
	if (req.file) {
		res.json({size: req.file.size})
	}
})

// process.env.PORT
app.listen(3000)
console.log('Server running on port 3000');

From what I have been able to figure out from the documentation, a folder called ‘uploads’ is created into which the files are uploaded. However the code does not work (the files are not uploaded in the folder). Also is there a way to avoid all the uploading?

According to Multer:

##MemoryStorage
The memory storage engine stores the files in memory as Buffer objects. It doesn’t have any options.

var storage = multer.memoryStorage()
var upload = multer({ storage: storage })

When using memory storage, the file info will contain a field called buffer that contains the entire file.

WARNING: Uploading very large files, or relatively small files in large numbers very quickly, can cause your application to run out of memory when memory storage is used.

Also:

NOTE: Multer will not process any form which is not multipart (multipart/form-data).

You can add an enctype like this:
<form action="demo_post_enctype.asp" method="post" enctype="multipart/form-data"> (HTML form enctype Attribute)

1 Like