upload文件失败

老师您好:

       我这边用nginx的upload模块做了一个简易文件服务器,由于上传上来的文件经过nginx后会自动加密,为了保持源文件名,搜索到了一个js程序,对上传的文件进行文件名字的转换,但是在使用过程中发现有大量的错误日志如下:

2020/08/04 05:57:26 [alert] 30596#0: *508475 aborted uploading file "log_1064811520685_20161128001500.tar.gz" to "/home/nginx/log/0000253566", dest file removed, client: IP, server: localhost, request: "POST /upload HTTP/1.1", host: "IP:PORT"

我的nginx upload模块配置如下:       

location /upload {

upload_pass /res_upload;
upload_store /home/nginx/log/;
upload_resumable on;
###node rename parm
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
}

location /res_upload {
#default_type text/html;
#return 200 "success";
proxy_pass http://localhost:8090;
}


其中用到的rename.js如下

const http = require('http');
const fs = require('fs');

http.createServer((req, res) => {
let body = '';
req.on('data', chunk => {
body += chunk; // 获取form-data
});
req.on('end', () => {
console.log(body);
const params = parseForm(body); // json化参数
rename(params.file_path, params.file_name);
res.end('success: you can get it from: /' + params.file_name);
})
}).listen(8090)

function parseForm(data) {
const reg = /name="([\w_]+)"\s+(.+)\s/g;
const params = {};
let matched;
while((matched = reg.exec(data))){
params[matched[1]] = matched[2];
}
console.log(params);
return params;
}

function rename(source, name){
const path = require('path');
const dir = path.dirname(source);
fs.renameSync(source, path.join(dir, name));
}

百度未找到解决方法,还望老师指点一二



邀请回答
提问于 2020-08-13 14:32
362 次浏览
共0个回答

发表评论
提问者

彧彧

i am a fish

  • 0

    文章

  • 0

    粉丝

  • 0

    被赞

彧彧
按Enter键发送
您已邀请位用户
版权所有©F5 Networks,Inc.保留所有权利。京ICP备16013763号-5