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;
    }           
}
Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
Dipali Wagh
  • 85
  • 1
  • 11
  • 1
    Why don't you write the conents of `imageBytes` to disk directly? – C.Evenhuis Sep 17 '14 at 07:55
  • possible duplicate of [A generic error occurred in GDI+. (Only if i try it on the server)](http://stackoverflow.com/questions/6035346/a-generic-error-occurred-in-gdi-only-if-i-try-it-on-the-server) – Paul Zahra Sep 17 '14 at 08:07

1 Answers1

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
                  );
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325