项目使用node,运行在linux平台上。有一个图片上传的接口,图片上传使用formidable 应为上传的人多了,出现linux(/tmp 目录)过饱和的情况,请求帮助。
上传图片核心代码:
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
var fileReadStream = fs.createReadStream(old_path);
var fileWriteStream = fs.createWriteStream(new_path);
fileReadStream.pipe(fileWriteStream);
})
现在的解决办法是linux 定期清理缓存区,我想的是node能定时清理内容。希望能在node上解决。linux不太熟悉,有办法也可以说出来。
Use scheduled tasks and pay attention to whether the user has permission to delete
Clean up files under the
at 3.30 am every day/tmp
directory修改
that are one week oldClean up every Monday and Thursday at 3.30am
/tmp
There are files in the directory that have not been访问
for a weekFind based on timestamp:
Time-related options include -atime, -ctime and -mtime [-atime represents the access time; -ctime represents the time when the file status is changed; -mtime represents the time when the file content is modified],
Explain with -mtime
You can write the image to a large file and read it from the large file every time you read the file.