¿Puedo subir imágenes y texto usando UrlEncodedFormEntity para multipartes?

Las imágenes suelen requerir encabezados HTTP especiales como:

Content-disposition: attachment; filename="file2.jpeg" Content-type: image/jpeg Content-Transfer-Encoding: binary 

Estoy construyendo mi POST usando:

 List<NameValuePair> formparams = new ArrayList<NameValuePair>(); UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams); 

UrlEncodedFormEntity permite setContentType, pero no veo cómo puedo MEZCLAR las imágenes y el texto ??

 try { File file = new File(Environment.getExternalStorageDirectory(),"FMS_photo.jpg"); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://homepage.com/path"); FileBody bin = new FileBody(file); Charset chars = Charset.forName("UTF-8"); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("problem[photos_attributes][0][image]", bin); reqEntity.addPart("myString", new StringBody("17", chars)); post.setEntity(reqEntity); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { resEntity.consumeContent(); } return true; } catch (Exception ex) { globalStatus = UPLOAD_ERROR; serverResponse = ""; return false; } finally { } 

En este atributo del problema llevará la imagen y myString llevar la cadena …

  • Android con Retrofit2 OkHttp3 - Error POST de varias partes
  • Implementación de ProgressDialog en la solicitud de subida múltiple
  • Cargar archivos en el servidor mediante retroadaptación
  • Uso de MultipartTypedOutput
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.