Upload images to a mysql database from android

-2

I use these two methods to try to insert an image to a database from an Android application, my problem is that the images are not inserted in the database, the webservices if it works because I use it to do tests in HTML, the one that does not work is that of the app, says that the code is obsolete, and does not compile.

<?php         
include ("conexion.php");
$imagp= base64_decode($_POST['imgP']);
$imgv= base64_decode($_POST['imgV']);
$nombre=$_POST['nombre']; 
$query = "INSERT INTO imagen (imgP,imgV,nombre ) VALUES ('$imagp','$imgv','$nombre')";
 try {
$resultado = $conexion->query($query);
$resultado = array();
    $resultado["success"] = false;  
    echo json_encode($resultado);
} catch (Exception $e) {
    echo $e ;
}
if ($resultado){
    echo " se inserto";
}
else{
    echo "no se inserto";
}

 ?>

This is the one that tries to use to send the bitmap, but it is obsolete, the code is not mine.

private void enviar() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://192.168.100.110/SS/agregar.php");
        Bitmap bm = BitmapFactory.decodeFile(mapa);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] byteArray = stream.toByteArray();
        List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("nombre", imageName));

        nameValuePairs.add(new BasicNameValuePair("igmP",
                Base64.encodeToString(byteArray, Base64.DEFAULT)));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
    } 
    
asked by jaron cascante Pérez 27.10.2016 в 23:56
source

1 answer

1

Did you try to convert the image to a Base64 String and send it to the MySQL database?

try
        {
            //Se obtiene el bitmap del image
            Bitmap bitmap = ((BitmapDrawable)_imgDenuncia.getDrawable()).getBitmap();

            //se convierte a un arregleo de bytes
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

            byte[] byteArray = stream.toByteArray();
            String imagen = Base64.encodeToString(byteArray, Base64.DEFAULT);

            _denuncia.setMimagen(imagen);
        }
        catch (Exception e)
        {
            _denuncia.setMimagen("");
        }

Greetings.

    
answered by 28.10.2016 / 01:11
source