0

I m sending base64string from android app to webservice. webservice converts that base64string into image again. But i m getting below error from web service while converting base64string into image again:

"A generic error occurred in GDI+." this error i m getting on server only.

below is my code:

public string Base64ToImage(string base64String, string imgName)
{
    try
    {
        // Convert Base64 String to byte[]
        byte[] imageBytes = Convert.FromBase64String(base64String);
        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

        // Convert byte[] to Image
        ms.Write(imageBytes, 0, imageBytes.Length);
        System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);

        image.Save(
            "D:\\apps\\PJP_TEST\\PJPTest\\Online\\ImageStorage\\" + imgName);

        return "Success";
    }
    catch (Exception ex)
    {
        return ex.Message;
    }           
}
2

1 Answer 1

4

I guess with 'server' you mean 'web server'. You probably have no rights to write in the folder D:\apps\PJP_TEST\PJPTest\Online\ImageStorage.

Check if the user that the application is running on has read and write access to the specified folder.

As said, it is easier to write the file directly:

File.WriteAllBytes( Path.Combine
                    ( @"D:\apps\PJP_TEST\PJPTest\Online\ImageStorage\"
                    , imgName
                    )
                  , imageBytes
                  );
Sign up to request clarification or add additional context in comments.

6 Comments

You'd expect an IOException if that where the case, not a GDI+ error.
@AVee: Too bad. It really is.
You're right, it indeed throws a System.Runtime.InteropServices.ExternalException. And yeah, I'd consider that pretty bad (but that doesn't make it less true).
@AVee: It is really obscure, but this is the error message you get when a file can't be written. I guess there is some low level Windows stuff going on in that method.
That's exactly what I just did :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.