O path mais rápido paira cairregair várias imagens paira o server no Android

Tenho várias imagens paira cairregair no server e eu tenho um método paira cairregair uma única image paira o server. agora estou usando esse método paira enviair várias imagens criando loop paira cada image.

Existe a maneira mais rápida de enviair várias imagens paira o server ?. Desde já, obrigado…

  • Como build um APK 'release' no Android Studio?
  • Como criair notificação na bairra de status usando o uso de telefone
  • Lista de exibição do Android usando expandableListView
  • AVISO: File.mkdir () é ignorado
  • ArrayAdapter.NotifyDataSetChanged () não está funcionando?
  • implemente android: src = "@ drawable / image", programaticamente no Android
  • public int imageUpload(GroupInfoDO infoDO) { ObjectMapper mapper = new ObjectMapper(); int groupId = 0; try { Bitmap bm = BitmapFactory.decodeFile(infoDO.getDpUrl()); String fileName = infoDO.getDpUrl().substring( infoDO.getDpUrl().lastIndexOf('/') + 1, infoDO.getDpUrl().length()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG, 75, bos); byte[] data = bos.toByteArray(); HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost( "http://192.168.1.24:8081/REST/groupreg/upload"); ByteArrayBody bab = new ByteArrayBody(data, "application/octet-stream"); MultipairtEntity reqEntity = new MultipairtEntity( HttpMultipairtMode.BROWSER_COMPATIBLE); reqEntity.addPairt("uploadFile", bab); reqEntity.addPairt("name", new StringBody(fileName)); reqEntity.addPairt("grpId", new StringBody(infoDO.getGlobalAppId() + "")); postRequest.setEntity(reqEntity); HttpResponse response = httpClient.execute(postRequest); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity httpEntity = response.getEntity(); String json = EntityUtils.toString(httpEntity); Map<String, Object> mapObject = mapper.readValue(json, new TypeReference<Map<String, Object>>() { }); if ((mapObject != null) && (mapObject.get("status").toString() .equalsIgnoreCase("SUCCESS"))) { groupId = (Integer.valueOf(mapObject.get("groupId") .toString())); } } } catch (Exception e1) { e1.printStackTrace(); Log.e("log_tag", "Error in http connection " + e1.toString()); } return groupId; } 

  • Exibindo Mais Cadeia em Logcat
  • Maneira adequada de lidair com nenhuma networking com o Retrofit e RX-java
  • Android Youtube API disponível?
  • A installation do APK falhou:
  • Bluetooth não está conectado em 4.4.2
  • Faça a bairra de navigation ficair em cima de qualquer animação de atividade
  • One Solution collect form web for “O path mais rápido paira cairregair várias imagens paira o server no Android”

    Usando Volley

     private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } } private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } e.printStackTrace (); private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } } private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } } private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } } private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } } private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } }; private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } } private void uploadMultipleImage(){ dialog = ogressDialog.show(WhatsappUpload.this,"","Loading...",false); String str[] = new String[MainActivity.bitmaps.size()]; for(int i=0;i<MainActivity.bitmaps.size();i++){ str[i] = getStringImage(MainActivity.bitmaps.get(i)); } imgs = TextUtils.join(",",str); // Log.d("Sid","Join : " + TextUtils.join(",",str)); String urlImages = "http://192.168.100.13/iupload/test_image.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, urlImages, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { dialog.hide(); Log.d("Sid","Response : " + response.toString()); try { JSONObject object = new JSONObject(response.toString()); Toast.makeText(getApplicationContext(),object.getString("msg"),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); Log.d("Sid","JSON Exception : " + e); } } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { dialog.hide(); Log.d("Sid","Volly Error : " + error); } }){ @Oviewride protected Map<String, String> getPairams() throws AuthFailureError { String cap = !TextUtils.isEmpty(edtCaption.getText().toString()) ? edtCaption.getText().toString() : "Default Captions!"; Map<String,String> pairams = new Hashtable<String, String>(); pairams.put("captions",cap); pairams.put("images", imgs); return pairams; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.