Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got problem when I choose picture with size 500 Kb from my gallery and my application force close. But if i choose picture with size 100-250kb it is success load image and send base64 to my database. Could you help me how to fix it ?

It is message error when i choose picture with 500kb:

   Refit.ApiException: 'Response status code does not indicate success: 500 (Internal Server Error).'


What I have tried:

This is my coding from mobile app:

async void SavePicture(object sender, EventArgs e)
 {
        file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
        {
            PhotoSize = PhotoSize.Small
            //CompressionQuality = 100,

        });

        if (file == null)
            return;


        //Convert image to string
        FileStream fs = new FileStream(file.Path, FileMode.Open, FileAccess.Read);
        byte[] ImageData = new byte[fs.Length];
        fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
        fs.Close();
        string imgResized = Convert.ToBase64String(ImageData);

        imageResize.Source = file.Path;

        api = RestService.For<ApiInterface> 
        ("http://192.168.0.190/webservice/webservice.asmx");

        String idgoogle = "";

        var id = Application.Current.Properties["Id"].ToString();

        var stringimage = imgResized;


        User user = new User(idgoogle);
        user.Profile_Image = stringimage;
        user.Id = id;


        var responseupdate = await api.UpdateGoogle(new UpdateGoogleQuery(user));

        if (responseupdate.isSuccess)
        {
            Loading.toast("Sukses Menyimpan Foto");
        }
        else
        {
            LoadingFailed.toast("Gagal Menyimpan Foto");
        }

}


This is my coding from webservice

public void update(User dtGoogle)
{
        String sql = $"UPDATE google SET profile_image = ('{dtGoogle.Profile_Image}') WHERE id = ('{dtGoogle.Id}')";
        Connection.executeSql(sql);
}
Posted
Updated 26-Dec-19 20:23pm

We can't help: we don't have access to your DB and it's data, we don't have the rest of your code, and we wouldn't know to use it if we did. And you need your code running and it's actual data in order to work out what is going on.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
I already debug my code and i found my error in
var responseupdate = await api.UpdateGoogle(new UpdateGoogleQuery(user));

I already to insert value base64 from picture with size 500kb to my webservice it is success add value base64 in my database.
 
Share this answer
 
Comments
Reyhan M.T 2-Jan-20 2:03am    
I try use log entry in my webservice it is success created if i choose picture with size 100kb - 490kb but if i choose picture with size 500kb my log entry don't created

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900