Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Dewayne Thomas
PLUS
Dewayne Thomas
Courses Plus Student 10,283 Points

XAMARIN C# Image not saving to mysql database

I'm trying to save a picture to my mysql database using base64string. I can take a picture or open he picture from my gallery and show it on screen. From there i try to save it. it saves all data except my image. i have stepped through my code to verify that it was converted to base64string but the db shows blob - 0' i am using a medium blob. if i convert online using a base64 converter then doing a save through an sql using phpmyadmin statement it works. but from my app it doesn't.

Please see my code below...

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();
        }

    }