How to return filename?
See original GitHub issueI would like to return the randomly generated file name back so that the front end can store the filename in the db, but I can’t figure out how to use the callback to return the filename to somewhere I can use res.send to send it out. Here’s my code:
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, '../images/');
},
filename: function (req, file, cb) {
var id = util.random_string(16) + Date.now() + path.extname(file.originalname);
cb(null, id);
}
});
var upload = multer({ storage: storage }).single('image');
router.post('/image/', function (req, res) {
upload(req, res, function (err) {
if (err){
console.log(JSON.stringify(err));
res.status(400).send("fail saving image");
} else {
res.send('how can I return the file name?');
}
});
});
Issue Analytics
- State:
- Created 8 years ago
- Reactions:7
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Insert the current Excel file name, path, or worksheet in a cell
Insert the current file name and the name of the active worksheet · To enter a formula as an array formula, press CTRL+SHIFT+ENTER....
Read more >Get File Name / Excel Formula - Excel Champs
How to Get File Name in Excel · First, use the SEARCH function to know the position of the starting square bracket by...
Read more >Insert File Name - Excel Formula
File Name, Path, and Worksheet We use the CELL Function to return the file path, name, and sheet by entering “filename” as the...
Read more >How to Get filename in Excel
In this article, we will learn How to Get filename in Excel. Scenario: Working with excel file information using excel formula is easy,...
Read more >How to Extract filename from a given path in C# ...
A path may contain the drive name, directory name(s) and the filename. To extract filename from the file, we use “GetFileName()” method of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Louis,
For people who are struggling with this issue.
The filename is in the res.req.file.filename variable. In your code it would look like this:
Look under “File information” in the documentation.