2

안녕하세요 Android의 웹 서버에 비디오 파일을 업로드하고 싶습니다. 나는이 자습서 다음 :안드로이드에서 웹 서버에 비디오 파일을 업로드하는 방법은 무엇입니까?

Uploading files to HTTP server using POST on Android.

을하지만. 내 logcat 에서이 오류가있어. 그리고 나는 서버로부터 메시지를 받았다.

09-11 10:20:55.088: D/dalvikvm(284): GC_FOR_MALLOC freed 1137 objects/74200 bytes in 70ms 
09-11 10:20:55.768: I/dalvikvm-heap(284): Grow heap (frag case) to 3.611MB for 1048592-byte allocation 
09-11 10:20:55.918: D/dalvikvm(284): GC_FOR_MALLOC freed 202 objects/10144 bytes in 142ms 
09-11 10:20:56.178: D/dalvikvm(284): GC_FOR_MALLOC freed 86 objects/3424 bytes in 91ms 
09-11 10:20:56.568: I/dalvikvm-heap(284): Grow heap (frag case) to 5.601MB for 2097364-byte allocation 
09-11 10:20:56.868: D/dalvikvm(284): GC_FOR_MALLOC freed 2 objects/56 bytes in 304ms 
09-11 10:20:57.178: D/dalvikvm(284): GC_FOR_MALLOC freed 4 objects/1120 bytes in 48ms 
09-11 10:20:57.748: I/dalvikvm-heap(284): Grow heap (frag case) to 11.600MB for 6291668-byte allocation 
09-11 10:20:57.918: D/dalvikvm(284): GC_FOR_MALLOC freed 0 objects/0 bytes in 168ms 
09-11 10:21:24.827: I/uploadFile(284): HTTP Response is : OK: 200 
09-11 10:21:24.847: E/Debug(284): Server Response There was an error uploading the file, please try again! 
09-11 10:21:24.858: I/System.out(284): RES : 200 
09-11 10:21:24.997: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: [email protected] 
09-11 10:23:34.277: DEBUG/SntpClient(59): request time failed: java.net. Socket Exception: Address family not supported by protocol 

동영상 파일을 wowza 미디어 서버에 업로드하고 싶습니다. 어떻게 해결할 수 있습니까? 그리고 어떻게 wowza 서버에서 진행할 수 있습니까? 아무도 나를 이룰 수 있습니까? 미리 감사드립니다.

답변

0

큰 크기의 비디오 때문입니다. 대용량 파일/비디오에 청크 업로드 방식을 사용합니다.

다음은 서버에 청크 데이터를 게시하는 샘플 코드입니다.

public void upload(String filename, byte[] image) { 
    // 1MB of chunk 
    byte[][] divideByte = divideArray(image, ((1024 * 1024)/2)); 
    int length = divideByte.length; 
    String token = "" + (int)System.currentTimeMillis(); 
    Log.i("System out", "divideByte:" + length); 
    Log.i("System out", "token:" + token); 

    for (int i = 0; i < length; i++) { 
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

     String link = "<your link>"; 

     nameValuePairs.add(new BasicNameValuePair("filename", filename));// filename 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost(link); 
     Log.i("System out", "divideByte[" + i + "] length :" 
       + divideByte[i].length); 
     String img = Base64.encodeBytes(divideByte[i]); 
     nameValuePairs.add(new BasicNameValuePair("file64", img)); 

     nameValuePairs.add(new BasicNameValuePair("token", new String("" 
       + token))); 
     nameValuePairs.add(new BasicNameValuePair("chunksize", new String(""+ 
       divideByte[i].length))); 
     nameValuePairs.add(new BasicNameValuePair("chunkcount", new String(
       "" + length))); 
     nameValuePairs.add(new BasicNameValuePair("index", new String("" 
       + i))); 
     try { 
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
      HttpResponse response = httpclient.execute(httppost); 
      HttpEntity httpEntity = response.getEntity(); 
      if (httpEntity != null) { 
       String res = EntityUtils.toString(httpEntity).toString(); 
       Log.i("System out", "response is :" + res);     
      } 
      httpEntity = null; 
      response = null; 
     } catch (Exception e) { 
      e.printStackTrace(); 
     }finally{ 
      httppost = null; 
      httpclient = null; 
     }   
    } 
} 

public static byte[][] divideArray(byte[] source, int chucksize) { 

    byte[][] ret = new byte[(int) Math.ceil(source.length 
      /(double) chucksize)][chucksize]; 

    Log.i("System out","ret: "+ret.length); 
    int start = 0; 

    for (int i = 0; i < ret.length; i++) { 
     if (start + chucksize > source.length) { 
      System.arraycopy(source, start, ret[i], 0, source.length 
        - start); 
     } else { 
      System.arraycopy(source, start, ret[i], 0, chucksize); 
     } 

     start += chucksize; 
    } 

    return ret; 
} 

그리고 서버 측에서 모든 청크 색인을 현명하게 얻고 하나의 비디오 파일을 작성하십시오.

도움을 받으십시오.

1

바이트 []에서 서버로 비디오를 보내면 outOfMemoryError가 MultiPart에서 비디오를 게시하는 것이 좋습니다. 이 링크에서 jar 파일을 다운로드 할 수 있습니다. http://hc.apache.org/downloads.cgi. httpmime-4.2.jar을 다운로드하여 프로젝트에 추가하십시오.

public void uploadVideo(Context context, String videoPath) { 
     try { 
      HttpClient httpClient = new DefaultHttpClient(); 
      HttpPost postRequest = new HttpPost(context.getString(R.string.url_service_fbpost)); 
      MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
      if(!videoPath.isEmpty()){ 

       FileBody filebodyVideo = new FileBody(new File(videoPath)); 
       reqEntity.addPart("uploaded", filebodyVideo); 
      } 
      postRequest.setEntity(reqEntity); 
      HttpResponse response = httpClient.execute(postRequest); 

      BufferedReader reader = new BufferedReader(new InputStreamReader(
        response.getEntity().getContent(), "UTF-8")); 
      String sResponse; 
      StringBuilder s = new StringBuilder(); 

      while ((sResponse = reader.readLine()) != null) { 
       s = s.append(sResponse); 
      } 

      Log.e("Response: ", s.toString()); 
      return true; 

     } catch (Exception e) { 
      Log.e(e.getClass().getName(), e.getMessage()); 
      return false; 
     } 
} 
관련 문제