📜  删除 nodejs 中的附件 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:37.928000             🧑  作者: Mango

代码示例1
// NOTE: `file_name` values are obfuscated and uniquely generated by the client.
// The actual file name is in data storage.
app.post('/delete/:file_name', (req, res) =>
{
    const theFile = 'attachments/' + req.params.file_name;

    var resultHandler = function(err) { 
        if(err) {
           console.log("file delete failed", err);
           return res.status(500).json(err)
        }
        console.log("file deleted");
        return res.status(200).send({data: req.params.file_name + ' deleted'});
    }
    
    fs.unlinkSync(theFile, resultHandler);
});