node.js - node 上传图片 造成linux 缓存区内容过多 怎么解决?
伊谢尔伦
伊谢尔伦 2017-04-17 15:16:20
0
2
497
  1. 项目使用node,运行在linux平台上。有一个图片上传的接口,图片上传使用formidable 应为上传的人多了,出现linux(/tmp 目录)过饱和的情况,请求帮助。

  2. 上传图片核心代码:

  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不太熟悉,有办法也可以说出来。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
黄舟

Use scheduled tasks and pay attention to whether the user has permission to delete

# crontab -e

Clean up files under the /tmp directory 修改 that are one week old

at 3.30 am every day
30 3 * * * * /usr/bin/find /tmp -mtime +7 -type f -exec rm -rf {} \;

Clean up every Monday and Thursday at 3.30am/tmpThere are files in the directory that have not been 访问 for a week

30 3 * * * 2,4 /usr/bin/find /tmp -atime +7 -type f -exec rm -rf {} \;

Find based on timestamp:

    以天为单位(time):
        -atime [+|-] # 访问
        -mtime [+|-] # 修改
        -ctime [+|-] # 表示被改变文件状态的时间
    以分钟为单位(min)
        -min [+|-]
        ...
        

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

-mtime n:n为数字,意思是在n天之前的【一天之内】被更改过内容的文件;
-mtime +n:列出在n天之前(不含n天本身)被更改过内容的文档名;
-mtime -n:列出在n天之内(含n天本身)被更改过内容的文档名;
大家讲道理

You can write the image to a large file and read it from the large file every time you read the file.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template