I am trying for weeks to change the name of the file being downloaded. But still no luck. Instead of file name to be Chrysanthemum.jpg, it becomes the hash of the file, i.e. 241693260.jpg
In my back-end I am using Node.js and Express.js to handle file upload/download. I am hashing the file name and attributes to make sure files are not getting overwritten.
Here is the HTML code:
<a class="btn btn-info" href="http://localhost:3000/getAttachments?name=Chrysanthemum.jpg&type=image%2Fjpeg&size=879394&lastModified=1247549551674&extension=jpg" download="Chrysanthemum.jpg" target="_blank">Download File</a>
Here is my back-end:
app.use('/uploads', express.static(__dirname + "/uploads"));
app.get("/getAttachments", function (req, res) {
try {
var fileToBeSent = hashCode(req.query.name + req.query.type + req.query.size + req.query.lastModified + req.query.extension);
fileToBeSent += req.query.extension ? '.' + req.query.extension : '';
// res.sendFile("./uploads/" + fileToBeSent, {
// root: __dirname,
// "Content-Disposition": '"attachment; filename="' + (req.query.extension ? '.' + req.query.extension : '') + '"',
// "Content-Type": "application/octet-stream"
// });
res.redirect("/uploads/" + fileToBeSent);
} catch (err) {
console.log("an attempt to GET a file that doesn't exist.");
}
});
So as I am renaming the file name in my back-end, I am trying to rename file back to it's original name using HTML5 but I am not being successful.
UPDATE: Using the express's sendFile result in the same issue.
UPDATE: My server is uses cross-origin