2012-02-01 1 views
2

내가 MultipartEntity를 통해 파일을 업로드 할 아파치 HttpClient를 사용하고, 나는설정 사용자 지정 파일 이름이

FileBody uploadFilePart = new FileBody(binaryFile); 
MultipartEntity reqEntity = new MultipartEntity(); 
reqEntity.addPart("bin", uploadFilePart); 
reqEntity.addPart("comment", comment); 
httpPost.setEntity(reqEntity); 

HttpResponse response = httpclient.execute(httpPost); 
HttpEntity resEntity = response.getEntity(); 

System.out.println("----------------------------------------"); 
System.out.println(response.getStatusLine()); 
if (resEntity != null) { 
    System.out.println("Response content length: " + 
         resEntity.getContentLength()); 
} 
EntityUtils.consume(resEntity); 

도움말이 높이 평가 ... 다음은 내 코드입니다 .. 다른 파일 이름으로 파일을 업로드해야합니다!

감사합니다, Surez

답변

6

다음과 같은 FileBody 생성자를 사용하여 파일 이름을 설정할 수 있습니다.

public FileBody(File file, 
       String filename, 
       String mimeType, 
       String charset) 
+0

It Works! 감사합니다. – Surez

+0

FYI는 최신 릴리스에서 더 이상 사용되지 않지만 여전히 생성자에서 이름을 설정할 수 있습니다. – Amber