Android Question [SOLVED] PostString and PostBytes don't return the "+" sending Blob

manuel_g

Member
Licensed User
Hi. Sorry for my english

I'm trying to send a Blob to MySQL, and StringUtils.EncodeBase64(The_Blob) retruns a string with lots of "+", for then sending that to the PHP method and use base64_decode() and do an SQL Insert... Of course it's not working beacuase the lost "+"


B4X:
Dim cadena As String = "p1=ABC+-*/123"
    Dim J1 As HttpJob
    J1.Initialize("",Me)
    'J1.PostString("https://agrosig.net/valleagro/metodos_privados_php/postPHP.php",cadena)
    J1.PostBytes("https://agrosig.net/valleagro/metodos_privados_php/postPHP.php",cadena.GetBytes("UTF8") )
    Wait For (J1) JobDone(job As HttpJob)
    If job.Success Then
        Log("getstring= "&job.GetString)
    End If

The PHP is just:
PHP:
<?php
$p1 = $_POST["p1"];
print  $p1;
?>

Log("getstring= "&job.GetString) ---> getstring= ABC -*/123

Using PostString or PostBytes the result is the same.

Why does the "+" dissapear?

Which method must I use to send strings thant contains "+"? Specially this Blob case.


Thank you!
 

TILogistic

Expert
Licensed User
Longtime User
test:

B4X:
    Dim su As StringUtils
    Dim url As String = "p1=ABC+-*/123"
    url = su.EncodeUrl(url, "UTF8")
    Log(url)
    url = su.DecodeUrl(url, "UTF8")
    Log(url)
 
Upvote 0

manuel_g

Member
Licensed User
test:

B4X:
    Dim su As StringUtils
    Dim url As String = "p1=ABC+-*/123"
    url = su.EncodeUrl(url, "UTF8")
    Log(url)
    url = su.DecodeUrl(url, "UTF8")
    Log(url)
Amazing! THANK YOU!!!

Finally I could take the Blob on my SQLite and insert it into MySQL!

B4X:
Dim su As StringUtils
Dim c As Cursor=bdd.ExecQuery("select blob_field from MyTable") 'Read the Blob on SQlite
    c.Position=0
Dim encoded As String = su.EncodeUrl(su.EncodeBase64(c.GetBlob("blob_field")),"UTF8") 'Encode the blob into Base64 then encode that into URL

Dim J1 As HttpJob
    J1.Initialize("",Me)
    J1.PostString("YourLink/PostMethod.php","p1="&encoded)

PHP:
<?php
//$conn ---> Connect to your MySQL data base...

mysqli_query($con,"SET CHARACTER SET utf8");
mysqli_query($con,"SET NAMES 'utf8'");

$p1=$_POST["p1"]

    $data=mysqli_real_escape_string($conn,base64_decode($p1));
    $query="insert into MyTable (blob_field) values ('". $data ."')";
    $sth = mysqli_query($con,$query);
?>

And now the SQLite's Blob was inserted on MySQL

And if you then need to go from MySQL to SQLite, here we're:

PHP:
<?php
//$conn ----> Connection to MySQL....
    
$res = mysqli_query($conn, "select BLob_field from YourTable ");
    $r = mysqli_fetch_assoc($res);

print base64_encode($r["Blob_field"]);
?>

B4X:
Dim J1 As HttpJob
    J1.Initialize("",Me)
    J1.Download("The_PHP_Method")
Wait For (J1) JobDone(job As HttpJob)
If job.Success Then
    Dim Buffer() As Byte = codifica.DecodeBase64(job.GetString)
    bdd.ExecNonQuery2("insert into yourtable (blob_field) values (?)",Array As Object(Buffer))
end if
 
Last edited:
Upvote 0
Top