Welcome! Log In Create A New Profile

Advanced

Image from hfsql to php webservice

Posted by marcov 
Image from hfsql to php webservice
September 02, 2022 03:57PM
hi,

I have an Android device where I store images and data in hfsql, then I have to send them via json to a php webservice via HTTPSend.
i have try this:

sTest is string =QRY_Photos.Path
sFoto is string = CompleteDir(fCurrentDir()) + sTest

vRequest	is Variant
sTipoRic  = "Add"
vRequest.Tipo_Ric		= sTipoRic
vRequest.Descrizio		= "test" 
vRequest.Image = Encrypt(fLoadBuffer(sFoto),"",cryptNone,encodeBASE64NoCR)


cMyRequest is httpRequest
cMyRequest.URL			= "[xxxxxxxx"]; // SERVER 
cMyRequest.ContentType	= "application/json"
cMyRequest.Content		= VariantToJSON(vRequest)
cMyRequest.Method		= httpPost
cMyResponse is httpResponse = HTTPSend(cMyRequest)



the data i receive in php is correct for the text fields but the image doesn't seem to arrive.
do you have any ideas?



Edited 1 time(s). Last edit at 09/02/2022 04:00PM by marcov.
pao
Re: Image from hfsql to php webservice
September 02, 2022 05:15PM
In your code you are sending the content of the file in CompleteDir(fCurrentDir()) + sTest and not the image stored in the HFSQL db, the only thing you are reading from the dd is the path of the file.

The file exists in the CurrentDir?

What is the content of vRequest.Image before converting to JSON?

Regards

Paulo Oliveira



Edited 2 time(s). Last edit at 09/02/2022 05:30PM by pao.
Re: Image from hfsql to php webservice
September 05, 2022 10:17AM
sorry, I tried both with the image saved in the db hfsql, and with the path (as in the posted code) but I didn't succeed in either way.


bufFoto is buffer =QRY_Photos.Photo

vRequest is Variant
sTipoRic = "Add"
vRequest.Tipo_Ric = sTipoRic
vRequest.Descrizio = "test"
vRequest.Image = bufFoto


cMyRequest is httpRequest
cMyRequest.URL = "[xxxxxxxx"]; // SERVER
cMyRequest.ContentType = "application/json"
cMyRequest.Content = VariantToJSON(vRequest)
cMyRequest.Method = httpPost
cMyResponse is httpResponse = HTTPSend(cMyRequest)
pao
Re: Image from hfsql to php webservice
September 05, 2022 05:06PM
Did you try with:
strFoto is string =encode(QRY_Photos.Photo,encodeBASE64)

vRequest is Variant
sTipoRic = "Add"
vRequest.Tipo_Ric = sTipoRic
vRequest.Descrizio = "test"
vRequest.Image = strFoto

Regards

Paulo Oliveira
Re: Image from hfsql to php webservice
September 06, 2022 12:27PM
hi,

i tried but it doesn't work.
I receive everything correctly except the image
Re: Image from hfsql to php webservice
September 07, 2022 04:11PM
hi,

i solved the problem, it was not the client but the server, for some reason the php base64_decode is not compatible with windev encode
Re: Image from hfsql to php webservice
September 07, 2022 05:41PM
Hi
I'm interested in a php web service? Is your database on a MySQL server?
I am interested in the procedure and the php code on the server side. Did you work on the web service with the help of WebDev? If you can give me some details or send me an email: infos.pilot@gmail.com
Thank you

[infosonline.net]
Re: Image from hfsql to php webservice
September 07, 2022 05:52PM
hi,

i dont use windev for webservice only php and mysql.
everything works correctly.
before inserting the file into mysql
$ fileName = addslashes ($ image);
Re: Image from hfsql to php webservice
September 07, 2022 09:30PM
Hi
Can you send me a php script that does this?
Is it one script (php file) or are there more?

Thank you

[infosonline.net]
Re: Image from hfsql to php webservice
September 08, 2022 10:04AM
hi,
this is the php code (no windev) to read the received json and insert the image into mysql:

$json = file_get_contents('php://input');

$fileJson=json_decode($json);
$immagine=$fileJson->{'Image'};
$immagine2=base64_decode($immagine);
$fileName = addslashes($immagine2);

$sql = "INSERT INTO xxxxxx (descrizione,dettaglio,immagine,percorso) VALUES ('PROVA','TEST','$fileName','PROVA')";
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: