2011-10-03 681 views

Respuesta

19

Comprobar el código para el envío de imágenes con el título, subtítulo, nombre, etc.,

HttpClient httpClient = new DefaultHttpClient(); 
    HttpPost postRequest = new HttpPost("You Link"); 
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
    reqEntity.addPart("name", new StringBody("Name")); 
    reqEntity.addPart("Id", new StringBody("ID")); 
    reqEntity.addPart("title",new StringBody("TITLE")); 
    reqEntity.addPart("caption", new StringBody("Caption")); 
    try{ 
     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     bitmap.compress(CompressFormat.JPEG, 75, bos); 
     byte[] data = bos.toByteArray(); 
     ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg"); 
     reqEntity.addPart("picture", bab); 
    } 
    catch(Exception e){ 
     //Log.v("Exception in Image", ""+e); 
     reqEntity.addPart("picture", new StringBody("")); 
    } 
    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); 
    } 

Dónde mapa de bits es el mapa de bits de imagen.

Avísame si encuentras dificultades.

Gracias Venky.

+0

Excelente. ¿Qué pasa con la carga de videos? –

+0

+1 Gracias hombre. Salvaste mi día. Gracias de nuevo. – Sajmon

+0

Pero esto no está sucediendo en Android Studio @Venky –

Cuestiones relacionadas