2011-08-22 1 views
0

멀티 파트 포스트 요청을 사용하여 두 개의 문자열 매개 변수 (토큰 및 소스)와 모바일 장치에서 캡처 한 이미지 (jpeg 인코딩 된 바이트 [])를 업로드하려고합니다. 하지만 잘못된 요청으로 인한 오류가 발생하고 있습니다.이미지 업로드를위한 멀티 파트 http 요청

멀티 파트 게시 요청을 작성할 때 표기법에 대해 아직 확신 할 수 없습니다. 그래서 도움이되는 링크와 자료는 좋을 것입니다.

코드는 블랙 베리 자바 개발

//------------------------------------------------------------------------------// 

StringBuffer buffer = new StringBuffer(); 
String boundary = "[email protected]#$--"; 
byte[] image = byte[] from camera.getsnapshot; 

buffer.append(boundary+"\r\nContent-Disposition: form- data;name=\"token\"\r\n"+token+"\r\n"); 

buffer.append(boundary+"\r\nContent-Disposition: form- data;name=\"source\"\r\n"+"Blackberry"+"\r\n"); 

buffer.append(boundary+"\r\nContent-Disposition: form- data;name=\"file.jpg\";filename=\""+ "file.jpg"+"\""+"\n" + "Content- Type:image/jpeg"+"\n"+ "Content-Transfer-Encoding: binary" + boundary +"\r\n" +new String(image)); 
buffer.append("\r\n" + boundary + "\r\n"); 

String string = new String(buffer); 

byte[] post = string.getBytes(); 



HttpConnection connection = (HttpConnection)Connector.open(url); 

connection.setRequestMethod("POST"); 

connection.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, 
HttpProtocolConstants.CONTENT_TYPE_MULTIPART_FORM_DATA+ 
";boundary="+boundary); 

    connection.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH,String.valueOf(post.length));  

connection.setRequestProperty("User-Agent", "Profile/MIDP_2.0 Configuration/CLDC-1.0"); 
OutputStream postStream =connection.openOutputStream(); 
postStream.write(post,0,post.length); 
postStream.close(); 

입니다 \ ------------------------------- -------------------------------------------------- - \

+1

우리에게 오류를 보여주세요. –

답변