http协议无法上传超过10M文件到服务器

上传10M以下的没有问题,上传10M以上的就无法从服务器获得响应值,这是为什么,http协议如何实现大文件上传

URL url = new URL(ManageConfigUtils.IMG_UPLOAD_PATH);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Content-Type",
ContentType.multipart_form_data);
con.setRequestProperty("Charset", "UTF-8");
con.setInstanceFollowRedirects(true);
con.setDoOutput(true);
con.setDoInput(true);
con.setReadTimeout(300 * 1000);
con.setChunkedStreamingMode(1024 * 1024);
con.connect();

        StringBuffer buffer = new StringBuffer();
        buffer.append("\r\n--LamfireFormBoundaryucJiylDzwZWyoOSF\r\n");
        buffer.append("Content-Disposition: form-data; name=\"file\"; filename=\""
                + file.getFileName() + "\"\r\n");
        buffer.append("Content-Type: application/octet-stream\r\n\r\n");
        OutputStream os = new DataOutputStream(con.getOutputStream());
        os.write(buffer.toString().getBytes());
        InputStream is = file.getFileItem().getInputStream();
        byte[] filebuffer = new byte[10240];
        synchronized (filebuffer) {
            int length = -1;
            while (-1 != (length = is.read(filebuffer))) {
                os.write(filebuffer, 0, length);
            }
        }
        os.flush();
        buffer = new StringBuffer();
        buffer.append("\r\n--LamfireFormBoundaryucJiylDzwZWyoOSF\r\n");
        buffer.append("Content-Disposition: form-data; name=\"" + "filedir"
                + "\"\r\n");
        buffer.append("Content-Type: text/plain;charset=" + "UTF-8"
                + "\r\n\r\n");
        buffer.append(dir);
        os.write(buffer.toString().getBytes());

        os.flush();
        os.close();

        is = con.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                con.getInputStream()));
        String line = null;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        con.disconnect();
查看全部
aalijie
aalijie
2014/12/02 03:15
  • 服务器
  • http协议
  • 上传
  • 点赞
  • 收藏
  • 回答
    私信

2个回复