首页 > 解决方案 > 反应发布图像文件上传问题 - 仅限生产

问题描述

我正在尝试附加图像文件。如果在此处附加文件,我的客户端以某种方式没有发送任何内容。

它在 React(website) 和 React-Native Web View(rendering) 上。

游戏的坏处是,我无法跟踪客户端日志,这是移动浏览器问题的原因。

1)

const formData = new FormData();
formData.append('report[description]', text);
formData.append('token', localStorage.getItem('tempToken'));
formData.append('report[image]', new Blob([this.state.file], { type: 'image/png' }));
axios.post('/accept_report', formData)

2)

const config = {
   headers: {
     'content-type': 'multipart/form-data'
   }
}
formData.append('report[image]', this.state.file);
axios.post("/accept_report", formData, config)

标签: javascriptruby-on-railsreactjsreact-nativeaxios

解决方案


解决了:

因为,它仅在附加文件时发生。我的作品nginx限制了大文件。我只能上传大约 500kb 没有结束。

改变了nginx客户的体型。

http{
   #...
   client_max_body_size 10M; #or 100M it depends on yr preference.
   #...
}

推荐阅读