2012-02-18 4 views
0

MultipartEntity를 사용하여 3gp 오디오 파일을 내 서버에 업로드해야합니다. 이 코드를 사용하고 있지만 여전히 3gp 파일을 업로드 할 수 없습니다.android에서 MultiPartEntity를 사용하여 서버에 3gp 파일을 업로드하는 방법은 무엇입니까?

FileInputStream is = new FileInputStream(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ 
                        "/" + nameOfFile)); 
    byte[] data = IOUtils.toByteArray(is); 

        InputStreamBody isb = new InputStreamBody(new 
        ByteArrayInputStream(data),nameOfFile); 
        HttpClient httpclient = new DefaultHttpClient(); 
        HttpPost httppost = new HttpPost("http://www.****.com/places/uploadVideo"); 
        httppost.setHeader("Content-Type", "audio/3gpp"); 
        MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
         multipartContent.addPart("video", isb); 
         Log.d("Audio length", isb.getFilename()+" "+isb.getMediaType()+ isb.getMimeType()); 
         httppost.setEntity(multipartContent); 

         HttpResponse res =httpclient.execute(httppost); 
         InputStream input = res.getEntity().getContent(); 
          BufferedReader rd = new BufferedReader(new InputStreamReader(input,"UTF-8"),input.toString().length()); 
          String line; 
          StringBuilder sb = new StringBuilder(); 
          while ((line = rd.readLine()) != null) { 
           sb.append(line); 
          } 
          rd.close(); 
         String uploadresponse = sb.toString(); 

         Log.d("Upload Pic Response",uploadresponse); 

내가 실수를하고있는 곳을 알려주시겠습니까?

로그 캣 응답

02-18 19:58:51.912: D/Audio length(3157): 1329575327359.3gp applicationapplication/octet-stream 
02-18 19:58:52.412: D/dalvikvm(3157): GC_FOR_MALLOC freed 2359 objects/161592 bytes in 56ms 
02-18 19:58:54.002: I/Resources(3157): Loaded time zone names for en_US in 200ms. 
02-18 19:58:54.012: D/Upload Pic Response(3157): <strong>app/controllers/places_controller.php</strong> (line <strong>425</strong>)<pre class="cake-debug">Array( [controller] => places [action] => uploadVideo [named] => Array  (  ) [pass] => Array  (  ) [plugin] =>  [form] => Array  (  ) [url] => Array  (   [url] => places/uploadVideo  ))</pre>{"response":{"status":0,"mesg":"No Video data present in the request"},"data":null} 

답변

2

이것 좀보십시오.

File f1 = null; 
ContentBody cbFile, cbFile1; 
// videofilename is the entire path file for eg. /mnt/sdcard/12345abc.3gpp 
f1 = new File(videofilename); 


cbFile = new FileBody(f1, "video/3gpp"); 
mpEntity.addPart("uservideo", cbFile); 

이 기능이 작동하는지 알려주세요.

+0

해당 문제가 없습니다. 문제가 .M 확장명이 .3gp 인 오디오 파일을 업로드하는 중입니다. –

+0

이 로그에서 무엇을 얻고 있습니까? Log.d ("오디오 길이", isb.getFilename() + ""+ isb.getMediaType() + isb.getMimeType()); ?? –

+0

Kinldy chk, 내 질문에 logcat을 추가합니다. –

관련 문제