2017-08-17 1 views
0

私はHttpAsyncClientでJavaを使用していて、multipart/formを使用してサーバーに投稿リクエストを作成しようとしています。 2つのパラメータがあります:1つは文字列ですが、2つ目はfie/byte配列です。大規模なバイト配列でリクエストを実行する必要がある場合、次の例外が発生します。org.apache.http.ContentTooLongException:コンテンツの長さが長すぎます。MultipartFormEntity - 内容が長すぎます

この問題を解決する方法はありますか? Javaとこのエンティティを使用してマルチパート/フォームで大きなサイズのリクエストを作成するにはどうすればよいですか? rawContentだけのバイト配列である

final HttpPost post = new HttpPost(uri); 
final HttpEntity entity = MultipartEntityBuilder.create() 
       .addTextBody("name", fileName).addBinaryBody("file", rawContent, ContentType.APPLICATION_OCTET_STREAM, fileName) 
       .build(); 
post.setEntity(entity); 
return client.execute(post, null); 

:ここ

は、私のコードの一部です。

答えて

0

「この問題を解決する方法はありますか? MultipartFormEntityは私のクラス、Httpクライアントを使用してApacheのクラスではありません

@Override 
    public InputStream getContent() throws IOException { 
     if (this.contentLength < 0) { 
      throw new ContentTooLongException("Content length is unknown"); 
     } else if (this.contentLength > 25 * 1024) { 
      throw new ContentTooLongException("Content length is too long: " + this.contentLength); 
     } 
     final ByteArrayOutputStream outstream = new ByteArrayOutputStream(); 
     writeTo(outstream); 
     outstream.flush(); 
     return new ByteArrayInputStream(outstream.toByteArray()); 
    } 

    @Override 
    public void writeTo(final OutputStream outstream) throws IOException { 
     this.multipart.writeTo(outstream); 
    } 

} 
+0

MultipartFormEntity 『クラス:「 あなたにこのコードを試すことができます』。私はちょうどあなたが投稿したこのコードが既に存在していることを確かめています。 – baki1995

関連する問題