Note that there are some explanatory texts on larger screens.

plurals
  1. POSend a Picture or Image to php Server
    text
    copied!<p>I need to know the BEST way to load a bitmap and send it via http as a string, because i want to store it in a database. So could you help me with any ideas, please? </p> <p>Thanks in advance, Regards</p> <p>I had something this:</p> <pre><code>public byte[] ConvertBitmaptoBits(Bitmap src) { try{ ByteArrayOutputStream os=new ByteArrayOutputStream(); src.compress( android.graphics.Bitmap.CompressFormat.PNG, 100, (OutputStream)os ); src.compress(Bitmap.CompressFormat.PNG, 100, os); //bm is the bitmap object byte[] b = os.toByteArray(); return b; }catch(Throwable e) { //Toast.makeText(this, "Error en ConvierteBitmapAString: " + e.getMessage(), 30); Log.v("ConvierteBitmapACadena", "Error al Convertir la imagen a Cadena: " + e.getMessage()); return null; } } </code></pre> <p>In my SEND method i had something like this:</p> <pre><code>public void Send() //throws Exception { try { InputStreamBody isb=null; StringBody sImageString=null; Resources r = this.getResources(); Bitmap bmp = BitmapFactory.decodeResource(r, R.drawable.icon); byte[] objImageBits = ConvertBitmaptoBits(bmp); if(objImageBits !=null ){ isb = new InputStreamBody(new ByteArrayInputStream(objImageBits), "uploadedFile"); } HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(strPath); SimpleDateFormat sdfDateTime = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); String strCurDate = sdfDateTime.format(new Date(System.currentTimeMillis())); StringBody sCurDate = new StringBody(strCurDate); MultipartEntity multipartContent = new MultipartEntity(); if(objImageBits !=null) { multipartContent.addPart("uploadedFile", isb); } multipartContent.addPart("fechaequipo", sCurDate); postRequest.setEntity(multipartContent); HttpResponse response = httpClient.execute(postRequest); response.getEntity().getContent().close(); } catch (Throwable e) { Log.v("executeMultipartPost", "Error in executeMultipartPost: " + e.getMessage()); } } </code></pre> <p>But it seems i am not getting the uploadedFile. This is my php script:</p> <p> <pre><code>$file2 = (isset($_POST['uploadedFile'])) ? ( $_POST['uploadedFile'] ):(''); $fechaequipo = (isset($_POST['fechaequipo']) ) ? ( $_POST['fechaequipo'] ):(''); $fp = null; $log_file = 'log.txt'; if (!$fp) $fp = fopen($log_file, 'a') or exit("No se puede abrir: $log_file!"); fwrite($fp, "&lt;INI LOG&gt;" . date("d/m/Y") ."\n\r"); fwrite($fp, "Date : ". $fechaequipo . "\n\r"); fwrite($fp, "File2 : " . $file2 . "\n\r"); fwrite($fp, "&lt;END LOG&gt;" . date("d/m/Y") ."\n\r"); fclose($fp); </code></pre> <p>?></p> <p>Do I'm doing anything wrong? Thanks in advance!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload