xamarin没有将图像保存到mysql db

时间:2016-08-12 03:32:47

标签: php mysql xamarin base64

我正在尝试使用base64string将图片保存到我的mysql数据库。我可以拍摄照片或从我的画廊打开照片并在屏幕上显示。从那里我试图保存它。它保存除我的图像以外的所有数据。 我已经通过我的代码来验证它已转换为base64string但db显示blob - 0'我正在使用中等blob。 如果我使用base64转换器在线转换然后使用phopmyadmin语句通过sql进行保存它的工作原理。但从我的应用程序没有去。

private byte[] _picData;
    if (resultCode == Result.Ok)
    {
        if (requestCode == 2)
        {
            Uri selectedImage = data.Data;

            Bitmap mBitmap = null;
            try
            {
                mBitmap = Media.GetBitmap(this.ContentResolver, selectedImage);
                photo.SetImageURI(selectedImage);

                Stream stream = ContentResolver.OpenInputStream(data.Data);
                Bitmap bitmap = BitmapFactory.DecodeStream(stream);
                MemoryStream newStream = new MemoryStream();
                bitmap.Compress(Bitmap.CompressFormat.Webp, 100, newStream);
                _picData = newStream.ToArray();
            }
            catch (Java.IO.IOException e)
            {
                e.PrintStackTrace();
            }

        }



        WebClient client = new WebClient();
        System.Uri uri = new System.Uri("http://www.sbmgroup.ca/test/biteboard/meal.php");
        NameValueCollection parameters = new NameValueCollection();
        if (_type.Equals("takePicture") || _type.Equals("openPicture"))
        {
            parameters.Add("type", "add");
            parameters.Add("user_id", _user_id.ToString());
            parameters.Add("meal", mealType);
            parameters.Add("scribble", scribble.Text);
            parameters.Add("feeling", _feelValue.ToString());
            parameters.Add("taste", _tasteValue.ToString());
            parameters.Add("date", date.ToString("yyyy-MM-dd H:mm:ss"));
            parameters.Add("picture", Convert.ToBase64String(_picData));
            client.UploadValuesAsync(uri, parameters);
            client.UploadValuesCompleted += Client_UploadValuesCompleted;
        }

我的php

<?php
    include("ConnectionInfo.php");
    global $type;
    global $id;
    global $user_id;
    global $meal;
    global $scribble;
    global $date;
    global $taste;
    global $feeling;
    global $picture;
    global $mealArray;

    $type = $_REQUEST['type'];
    $id = $_REQUEST['id'];
    $user_id = $_REQUEST['user_id'];
    $meal = $_REQUEST['meal'];
    $scribble = $_REQUEST['scribble'];
    $date = $_REQUEST['date'];
    $dateLike = "{$_REQUEST['date']}%";
    $taste = $_REQUEST['taste'];
    $feeling = $_REQUEST['feeling'];
    $picture = $_REQUEST['picture'];
    $mealArray = array();

    if ($type === "add")
    {
        $stmt = $conn->prepare('INSERT INTO meals (user_id,meal,comment,date,taste,feeling,mealPic) values(?,?,?,?,?,?,?)');
        $stmt->bind_param('isssiib',$user_id,$meal,$scribble,$date,$taste,$feeling,$picture);
        $stmt->execute();
        $stmt->store_result();
        $stmt->fetch();
        $newId = $conn->insert_id;
        echo $newId;
    }

我在没有帮助的情况下查看了类似的问题。

0 个答案:

没有答案