The*_*oor 2 download fs node.js express server
我正在开发一个应用程序,它有一个服务器,可以使用response.download(). (我正在使用 node.js、express 和 fs)一旦这些文件被下载,它们就会占用空间,所以我尝试fs.unlinksync在下载后调用以摆脱它们。但是没有这样的运气:我只是收到以下错误:NOENT: No such file or directory.
这是相关的服务器端代码:
app.get("/file", function(request, response) {
var filename = request.query.f;
var filePath = "public/" + filename
response.download(filePath);
//this is where I've tried putting fs.unlink
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。谢谢!
Ahm*_*bek 10
response.download 有回调函数,下载后可以删除文件,如下图
response.download(filePath, yourFileName, function(err) {
if (err) {
console.log(err); // Check error if you want
}
fs.unlink(yourFilePath, function(){
console.log("File was deleted") // Callback
});
// fs.unlinkSync(yourFilePath) // If you don't need callback
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3383 次 |
| 最近记录: |