Android Question How can I upload & download a photo to/from mysql through httpjob?

Alphaw

Member
Licensed User
Longtime User
Hello everyone,

I am going to do these things:
1. using php connect mysql with the php code (done already)
B4X:
<?php
    include ("DBconnect.php");

    $action = $_GET['action'];
    $photo = $_GET['photo'];

    switch ($action)
    {
        Case "send":
        $sql = "INSERT INTO `u907875456_test`.`phototesting` (`photo`) VALUES ('$photo');";
        mysql_query($sql);
    }
?>
To upload a by php code, we need to encode the photo into code, therefore:

2. how to I encode the photo?
The b4a code I will use like this:
B4X:
Sub button_Click
Private upload As HttpJob
upload.Initialize("photoupload", Me)
upload.download2("http://athrun999.16mb.com/photo.php", Array As String ("action", "send", "photo", XXXXXXX))
End Sub

XXXXXXX is the encoded photo, how can I generate it? Can anyone give me a hint, thank you.

3. How can I read that photo in the b4a application later on? Besides, if I want to download the photo, what is the process?

I am hoping to see any help!!!! Thank you.

Alpha
 

DonManfred

Expert
Licensed User
Longtime User
Sending x KB of Text (encoded image) with job.Download (GET-Request) will probably not work as it is too much data.
Use POST instead.
Or better directly use PostMultiPart

But away from this:
- It is not a good practice to store images in a Database. Usually it is better to store the images on your webserver and just store the path to this image in your database. If you need this images in your app you download it with httputils
 
Upvote 0
Top