Encode an image and pass it to a database

Is it necessary to compile an APP before testing ? I get inconsistent results from the same code.

This setup works for me (tested with companion app on Android 13), sending a picked image to the mySql db from Appinventor

DB Table Structure

PHP

<?php
// sube3.php 
// 1.- IDENTIFICACION nombre de la base, del usuario, clave y servidor
$db_host="localhost";
$db_name="fake"; // fake
$db_login="fake"; // fake
$db_pswd="fake"; // fake

// 2.- CONEXION A LA BASE DE DATOS
$link = new mysqli($db_host, $db_login, $db_pswd, $db_name);

// 3.- OBTENER ARCHIVO - GET FILE
  $file = file_get_contents('php://input');
   if (file_put_contents($_GET['archivo'],$file == TRUE))  {
   
		$filename = $_GET['archivo'];
		$extension = pathinfo($filename, PATHINFO_EXTENSION);
		// $extension = mime_content_type($filename);
		
		// Archivo a MySQLi. BLOB. - File to MysQLi BLOB.
		$imageBlob = mysqli_real_escape_string($link, $file);
		$resultado = mysqli_query($link, "INSERT INTO testTable (imageBlob, extn, filename) VALUES ('$imageBlob', '$extension', '$filename')");
		mysqli_close($link);	
		echo $filename." uploaded.";
   } else {
	echo "Error";  
   }
?>

BLOCKS

SCREEN

image

MYSQL DB TABLE

1 Like

Are you working on a localhost. I make these changes and the same result. The app inventor starts to lock up. Can I set up the APP inventor on local host ?

No, this is on a remote online server

You want to build your own appinventor from sources ? (this is not the problem)

Check your work again.....

Share your aia project for inspection (you can remove/replace your domain name)

I'm beginning to think my host Arvixe.com don't want me using the file_get_contents procedure as any script I have using it is not working. It's rediculas.

Why is the BLOB data not going into the database from App Inventor ??
It does work if I hard code an image into the URL so its not the PHP, Table or Host.
Here's the BLOCKS

which means "I hard code an image into the URL", can you give an example?

thamestales.co.uk/longbupl.php?imagen=XXXXX.php

Something like this works fine. But send it from APP inventor and it does not. Does the domain need to be https

sorry XXXX.jpg

The web component is not able to send multipart/formdata, see also

Taifun

Try

PostFile
path

Right. So you're saying this Request Headers does not work. What should it be ?

It is not needed.

I have tried that along with a lot of other versions. There is no BLOB data going to the PHP script.

Show your php file again

$link = new mysqli($db_host, $db_login, $db_pswd, $db_name);

//  $data = file_get_contents(basename($_GET["imagen"]));
  
 $data = file_get_contents('php://input');

     
      if (!(file_put_contents($_GET['imagen'],$data) === FALSE))  {

		$nombre = $_GET['imagen'];
		$extension = pathinfo($nombre, PATHINFO_EXTENSION);
		
		$blob = mysqli_real_escape_string($link, $data);
		
		$resultado = mysqli_query($link, "INSERT INTO drawings (image, extension, name) VALUES ('$blob', '$extension', '$nombre')");
		mysqli_close($link);
		
   } else {
	echo "Error no";  
   }

It can't be this if I can insert the BLOB data with the hard code.

Is is possible to do this ? Are phones set to prevent sharing images outside the Industry giants ?