我正在制作练习网络服务(客户端的艺术书显示网站)客户端可以将艺术图像上传到服务器。
但是当客户端上传过多图片时,我收到以下错误
@Override
protected void onMain_ButtonSubirAPIAction(Component c, ActionEvent event) {
String picture = Capture.capturePhoto(width, -1);
if(picture!=null){
String cloudinaryURL = "https://api.cloudinary.com/v1_1/"+CLOUDNAME+"/image/upload";
MultipartRequest request = new MultipartRequest() {
protected void readResponse(InputStream input) throws IOException {
JSONParser jp = new JSONParser();
Map <String, Object> result = jp.parseJSON(new InputStreamReader(input, "UTF-8"));
labelX.setText((String)result.get("url"));
}
};
request.setPost(true);
request.setHttpMethod("POST");
String encoded = Base64.encodeNoNewline((APIKEY + ":" + APISECRET).getBytes());
request.addRequestHeader("Authorization", "Basic " + encoded);
request.setUrl(cloudinaryURL);
try {
request.addData("file", picture, "image/jpeg");
request.addArgument("public_id", "name1");
NetworkManager.getInstance().addToQueue(request);
} catch(Exception err) {
}
}
}
我尝试在nginx.conf中添加413 Request Entity Too Large
client_max_body_size 100M;
并尝试:
#user nobody;
#Defines which Linux system user will own and run the Nginx server
worker_processes 1;
#error_log logs/error.log; #error_log logs/error.log notice;
#Specifies the file where server logs.
#pid logs/nginx.pid;
#nginx will write its master process ID(PID).
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
server {
listen 80;
server_name xxxx.net;
client_max_body_size 100M;
keepalive_timeout 5;
return 301 https://$server_name$request_uri;
}
# HTTPS server
#
server {
listen 443 default_server ssl;
server_name xxx.net;
ssl_certificate /etc/letsencrypt/live/xxxx.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxxx.net/privkey.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
}
}
}
并重试
sudo service nginx restart
sudo service nginx reload
但仍然得到
runserver
有人可以帮忙吗?
答案 0 :(得分:0)
您已解决HTTP服务器上的问题,但是HTTP服务器设置为301重定向到HTTPS服务器...您的HTTPS服务器未配置client_max_body_size
,因此默认为1M&导致此 413(请求实体太大)错误。
要解决此问题,您只需将client_max_body_size
添加到两者 HTTP服务器块 和 ,如下例所示:
http {
...
######################
# HTTP server
######################
server {
...
listen 80;
server_name xxxx.net;
client_max_body_size 100M;
...
}
######################
# HTTPS server
######################
server {
...
listen 443 default_server ssl;
server_name xxxx.net;
client_max_body_size 100M;
...
}
}
有关client_max_body_size
的更多信息,请访问:http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
语法:client_max_body_size大小;
默认值:client_max_body_size 1m;
上下文:http,服务器,位置
设置客户端请求正文的最大允许大小,在 “内容长度”请求标头字段。如果在请求中的大小 超过配置的值,则出现413(请求实体太大)错误 返回给客户端。请注意,浏览器无法 正确显示此错误。将大小设置为0将禁用对 客户请求正文大小。
在此处了解有关配置HTTPS服务器的更多信息:http://nginx.org/en/docs/http/configuring_https_servers.html