Hello,
I use the below code to upload files:
and on php site I use below code:
If I upload image with b4a it will be stored correct in sql database ("data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD...")
If I try to upload image with b4i it seems that no data will be arrived at database site, because only the header information "data:image/jpg;base64," will be stored in database.
TY
I use the below code to upload files:
B4X:
Dim FileUploadSQL As HttpJob
Dim fd As MultipartFileData
FileUploadSQL.Initialize("ProfilePictureUpload", Me)
fd.Initialize
fd.Dir = File.DirDocuments
fd.FileName = "profile_pic.jpg"
fd.KeyName = "file"
fd.ContentType = "multipart/form-data"
FileUploadSQL.PostMultipart(strHTTP & ServerIP & "/BQE/bqe_file_upload.php", CreateMap("action": "ProfilePictureUpload", "MitgliedsID": ActualProfile(0).MitgliedsID), Array(fd))
and on php site I use below code:
PHP:
$action = $_POST["action"];
switch ($action)
{
Case "ProfilePictureUpload":
$MitgliedsID = $_POST["MitgliedsID"];
$name = $_FILES['file']['name'];
// here you can detect if save it to directory
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif");
// Check extension
if(in_array($imageFileType,$extensions_arr) ){
// Convert to base64
$image_base64 = base64_encode(file_get_contents($_FILES['file']['tmp_name']));
$image = 'data:image/'.$imageFileType.';base64,'.$image_base64;
// Insert record
//$q = mysqli_query($con,"INSERT INTO images (image) VALUES ('$image')");
$q = mysqli_query($con,"UPDATE mitglieder SET ProfilBild = '$image' WHERE MitgliedsID = '$MitgliedsID'");
print json_encode("Upload erfolgrich");
// Upload file if needed
// move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$name);
}
print json_encode("Profilbild aktualisiert");
break;
}
If I upload image with b4a it will be stored correct in sql database ("data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD...")
If I try to upload image with b4i it seems that no data will be arrived at database site, because only the header information "data:image/jpg;base64," will be stored in database.
TY