2013-10-10 6 views
4

사진 및 비디오 촬영을위한 안드로이드 응용 프로그램을 만들고 있습니다. 이미지를 캡처 한 후 날짜와 일부 텍스트가있는이 이미지를 웹 서버에 보내려고합니다. 서버 측에서는이 사진과 비디오로 응용 프로그램을 만들고 있습니다. 캡처 된 이미지는 메모리 카드에 저장됩니다. JSON을 사용하여 텍스트가 포함 된 이미지를 보내려면 어떻게해야합니까? 또한 웹 서버에 비디오를 보내려고합니다.android에 서버에 이미지 및 비디오 보내기

답변

1

당신은 멀티 파트 POST 요청하여이 작업을 수행 할 수 있습니다 :이 mime4j 라이브러리를 추가해야

 HttpClient client = new DefaultHttpClient(); 
     HttpPost post = new HttpPost(serverURL); 
     MultipartEntity postEntity = new MultipartEntity(); 
     File file = new File("Your File path on SD card"); 
     postEntity.addPart("fileupload", new FileBody(file, "image/jpeg")); 
     postEntity.addPart("loginKey", new StringBody(""+loginKey)); 
     postEntity.addPart("message", new StringBody(message)); 
     postEntity.addPart("token", new StringBody(token)); 
     post.setEntity(postEntity); 
     response = client.execute(post); 

(이 방법을 사용하면 JSON을 만들 필요가없는).

+0

에서 서버에 텍스트, 이미지를 uplaod 시도는 파일 – Ameer

+0

모든 종류의 가능 예 ... 이미지 또는 비디오 ... 작동합니다 :) – amalBit

+0

PDF 파일은 무엇입니까 – Ameer

0

당신은 당신의 AsyncTask를이 코드를 사용할 수 있습니다

File file = new File("Your File path on SD card"); 
HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httpost = new HttpPost("YourUrl"); 

MultipartEntity entity = new MultipartEntity(); 
entity.addPart("YourKey",new StringBody("Your Text")); 
entity.addPart("File", new FileBody(file)); 
httpost.setEntity(entity); 


HttpResponse response = httpclient.execute(httpost); 
+1

예, amalBit에 따르면, apache-mime4j 라이브러리를 추가해야한다고 ... – Vikram

+0

이것은 가능한 라이브러리 httpp : //www.java2s.com/Code/Jar/h/Downloadhttpmime43jar.htm입니다. – sivi

1

이이 AsyncTask를

  FileBody filebodyVideo = new FileBody(new File(
        "Sd Card VideoPath")); 

      FileBody filebodyVideo1 = new FileBody(new File("Video Upload url")); 

      StringBody Title= new StringBody("Put Title Here"); 

      StringBody description= new StringBody("Put Desc Here"); 




      MultipartEntity reqEntity = new MultipartEntity(); 

      reqEntity.addPart("image", filebodyVideo); 

      multipartContent.addPart("Title", Title); 

      multipartContent.addPart("Description", description); 


      httppost.setEntity(multipartContent); 
관련 문제