2011-11-15 3 views
0

Android에서 새로 생겼습니다. wifi와 gprs를 통해 파일을 업로드하고 싶지만 문제는 어떻게 Android에서 다중 부분 데이터를 보낼 수 있는가입니다.Android 용 파일 업로드

답변

0

link에 대한 세부 정보는 이동해야합니다. 이것은 비슷한 질문입니다.

+0

저는 첫 번째 질문의 답을 알고 기쁩니다. 그것은 내가 원하는 것입니다. 시기 적절한 답변을 주셔서 감사합니다. – Leo

0

HttpConnection을 만들고 서버에 스트림을 전달합니다. 따르십시오 link

1
  // Enable HTTP parameters 
      HttpParams sslparams = new BasicHttpParams(); 
      HttpProtocolParams.setVersion(sslparams, HttpVersion.HTTP_1_1); 
      HttpProtocolParams.setContentCharset(sslparams, HTTP.UTF_8); 

      // Register the HTTP and HTTPS Protocols. For HTTPS, register our custom SSL Factory object. 
      SchemeRegistry registry = new SchemeRegistry(); 
      registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
      registry.register(new Scheme("https",sslFactory, 443)); 

      // Create a new connection manager using the newly created registry and then create a new HTTP client 
      // using this connection manager 
      ClientConnectionManager ccm = new ThreadSafeClientConnManager(sslparams, registry); 
      httpclient = new DefaultHttpClient(ccm,sslparams); 

      HttpPost httppost = new HttpPost(url); 
      /*httppost.setEntity(new UrlEncodedFormEntity(nameValue)); 
      httppost.setEntity(new InputStreamEntity(new FileInputStream(file), file.length())); 
      httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");*/ 
      MultipartEntity entity = new MultipartEntity(); 
      //entity.addPart("fileName",); 
      entity.addPart("file", new InputStreamBody(new FileInputStream(file), ContentType.APPLICATION_OCTET_STREAM)); 
      entity.addPart("UserID", new StringBody(parameter.getUsreId())); 
      entity.addPart("UserName",new StringBody(parameter.getUserName())); 
      entity.addPart("HostName", new StringBody(parameter.getHostName())); 
      entity.addPart("ProtectionType", new StringBody(parameter.getProtectionType())); 
      entity.addPart("FolderPath", new StringBody(parameter.getFolderPath())); 
      entity.addPart("osid", new StringBody(parameter.getOsId())); 
      //entity.addPart("file", new FileBody(file,ContentType.MULTIPART_FORM_DATA)); 
      httppost.setEntity(entity); 
      //httppost.setEntity(new StringEntity(file)); 
      //httppost.setHeader("Content-Type", "text/xml"); 

      HttpParams httpparams = new BasicHttpParams(); 
      HttpConnectionParams.setConnectionTimeout(httpparams, 15000); 
      HttpConnectionParams.setSoTimeout(httpparams, 30000); 
      httppost.setParams(httpparams); 
      HttpResponse response = httpclient.execute(httppost); 
관련 문제