问题描述
本地上传图片正常,只要部署到nginx超过100KB大小就会出现图片上传不完整。
nginx日志里没有报错,node也没报错。
问题出现的环境背景及自己尝试过哪些方法
操作系统是Windows,我尝试过百度修改nginx里面的配置文件,但是目前没发现有效果,是不是我没修改对?
刚才尝试了一下Apache上传,发现可以正常上传。
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
async upload_Img() {
console.log('开始上传');
const {
ctx
} = this;
const stream = await ctx.getFileStream();
if (!stream) {
ctx.throw(403, '文件不存在或者文件错误');
return false;
}
const date = await this.fliteDate(new Date());
const folder = `app/public/upload/img/${date}`;
const filename = new Date().getTime() + stream.filename;
const target = path.join(`${folder}/${filename}`);
let data = {};
const result = await new Promise((resolve, reject) => {
fs.access(folder, fs.constants.F_OK, err => {
if (err) {
fs.mkdir(folder);
}
const remoteFileStream = fs.createWriteStream(target);
const upwin = stream.pipe(remoteFileStream);
console.log('上传成功');
console.log(upwin);
if (upwin) {
const path = upwin.path.match(/public(.*)/g);
data = {
code: 0,
msg: '图片上传成功',
data: {
src: ctx.app.config.hostConfig.host + path[0]
}
};
resolve(data);
}
reject('上传失败');
});
});
return result;
}
Nginx配置
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
client_max_body_size 100M;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 8099;
location / {
root F:\kcyygzh\app\public;
index index.html;
try_files $uri $uri/ /index.html;
}
location ^~ /admin {
proxy_pass http://localhost:7001;
}
location ^~ /public {
proxy_pass http://localhost:7001;
}
location ^~ /v1 {
proxy_pass http://localhost:7001;
}
location ^~ /api {
proxy_pass http://localhost:7001;
}
location ^~ /home {
proxy_pass http://localhost:7001;
}
error_page 500 502 503 504 404 /50x.html;
location = /50x.html {
root html;
}
}