Sending Images by Post

Nator

Member
Licensed User
Longtime User
Hi, First of all, great Site, lot of info.

I have a question, I want to send an image (in byte array), y have the image in memory, but i don't know how to send it, any idea?

I use
B4X:
in.InitializeFromBytesArray(Data, 0, Data.Length) 'image taken from the camera
query="dbe9c2450553009d47e6597a725250ca,<imagen>"& in &"</imagen>"
req.InitializePost2("http://xxx.xxx.xxx.xxx/recive_respuesta_webservice_json.php", query.GetBytes("UTF8"))
But don't work it send
B4X:
dbe9c2450553009d47e6597a725250ca,<imagen>(ByteArrayInputStream) java.io.ByteArrayInputStream@4567be00</imagen>

Thanks for the help

PD: sorry for my english is not very good
 
Last edited:

Nator

Member
Licensed User
Longtime User
Sorry for no give an answer before, I try to use HttpUtils but it doesent work for me. But was a great example of codes so I fix my problemas (Just Today) so y want to shared with all of you, so some one with the same problema con fix it.

This way I capute de Image of the camera
B4X:
in.InitializeFromBytesArray(Data, 0, Data.Length)
   bmpImage.Initialize2(in)
   encode=su.EncodeBase64(Data)
   camera1.StopPreview
   btnTakePicture.Visible=False
   ImageView1.Enabled=True
   ImageView1.Visible=True
   ImageView1.Bitmap=bmpImage

Then this way I send it

B4X:
query=dbe9c2450553009d47e6597a725250ca,<imagen>"& encode &"</imagen>"
req.InitializePost2("http://xxx.xxx.xxx.xxx/recive_respuesta_webservice_json.php", query.GetBytes("UTF8"))
Main.hc.Execute(req, 0)

That was the Movil code, in php y use this for inserting the image in a mysql blop cell

PHP:
$imagen_decode=base64_decode($imagen);
$imagen_decode=addslashes($imagen_decode);

$sql="insert into table (foto) values('".$imagen_decode."')";

I hope that this info helps someone
 
Last edited:
Upvote 0

fbritop

Well-Known Member
Licensed User
Longtime User
Has someone has an example of posting an image and receiving it at a VB.Net endpoint.

I have tried to send it via base64 encoded parameter, after reading the byte() array to string, but the VB.net endpoint tells me that the encoded string recieved at the server, mismatchs the base64 length.

I have tried to post the file, but the VB.Net endpoint, does not recieved the file.

Has someone any example on the VB.net endpoint?

thanks
FBP
 
Upvote 0

fbritop

Well-Known Member
Licensed User
Longtime User
Thanks Erel,
The main problem relies than PostFile does not include the enctype does not transmit like a "multipart/form-data", so on the other end I cannot recieve the "files" collection in order to save the chunks.

Is there a way that HTTPUtils can include the enctype?

Thanks
FBP
 
Upvote 0

fbritop

Well-Known Member
Licensed User
Longtime User
Erel,
For everyone else help, I have done it with

B4X:
Dim Ruta as String = server.MapPath("/files/check.list/" & request.QueryString("idItem") & ".jpg")

Dim stream as Stream = Request.InputStream
    Using fileStream As FileStream = System.IO.File.Create(ruta, CInt(stream.Length))
        Dim bytesInStream(0 To stream.Length - 1) As byte
       stream.Read(BytesInStream, 0, CInt(bytesInStream.Length))
        fileStream.Write(bytesInStream, 0, bytesInStream.Length)
End using

Using:
HttpUtils.postbytes
 
Upvote 0
Top