express file upload mv
app.post('/upload-avatar', async (req, res) => {
try {
if(!req.files) {
res.send({
status: false,
message: 'No file uploaded'
});
} else {
//Use the name of the input field (i.e. "avatar") to retrieve the uploaded file
let avatar = req.files.avatar;
//Use the mv() method to place the file in upload directory (i.e. "uploads")
avatar.mv('./uploads/' + avatar.name);
//send response
res.send({
status: true,
message: 'File is uploaded',
data: {
name: avatar.name,
mimetype: avatar.mimetype,
size: avatar.size
}
});
}
} catch (err) {
res.status(500).send(err);
}
});
Also in JavaScript:
- jquery get 2nd child
- backbone js event listener
- jwt strategy
- get first element by class name jquery
- SFC in react
- object methods in javascript
- Removing duplicates in an Array of Objects
- how to write a program that alerts the first 3 letters of the current day in javascript
- drupal 8 check if current page is node
- append css file with javascript
- compare date and time in js
- ejecutar una funcion js con id html usando jquery
- toisodatestring
- swap scroll right in react native
- react style ternary operator
- javascript iterate over object
- typeerror undefined is not an object (evaluating 'navigation.navigate')
- javascript validate is not a function problem
- .join javascript
- send a message discordjs
- json_extract in non native query
- reverse a number in javascript without using inbuilt function
- ERROR TypeError: Cannot assign to read only property 'reportAirport' of object '[object Object]
- offset in js