Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:33:27+00:00 2026-05-26T01:33:27+00:00

I create an asp.net 4.0 web application which has a web service for uploading

  • 0

I create an asp.net 4.0 web application which has a web service for uploading images. I am uploading images by sending the image in form of Base64 string from my mobile app to the web service.

Following is my code:

public string Authenticate(string username, string password, string fileID, string imageData)
    {
        Dictionary<string, string> responseDictionary = new Dictionary<string, string>();
        bool isAuthenticated = true; // Set this value based on the authentication logic

        try
        {
            if (isAuthenticated)
            {
                UploadImage(imageData);

                string result = "success";
                var message = "Login successful";

                responseDictionary["status"] = result;
                responseDictionary["message"] = message;
            }
        }
        catch (Exception ex)
        {

            responseDictionary["status"] = ex.Message;
            responseDictionary["message"] = ex.StackTrace;
        }

        return new JavaScriptSerializer().Serialize(responseDictionary);
    }

    private void UploadImage(string uploadedImage)
    {
        // Convert Base64 String to byte[]
        byte[] imageBytes = Convert.FromBase64String(uploadedImage);
        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

        System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)Image.FromStream(ms);

        string uploadPath = Server.MapPath("..\\uploads\\") + DateTime.Now.Ticks.ToString() + ".jpeg";
        ms.Close();

        bitmap.Save(uploadPath, System.Drawing.Imaging.ImageFormat.Jpeg);
        bitmap.Dispose();
    }    

This code was working fine on my local ASP.NET development server and I was able to see the uploaded image in my “uploads” directory. However, after transferring the code to the FTP directory, I am now getting the following error:

A generic error occurred in GDI+

I have checked that the upload directory has proper permission by creating a dummy .aspx page and creating a text file on page_load, and it works fine.

Even after doing google search, I was not able to solve this problem. Can anybody help me fixing this?

Thanks a lot in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:33:28+00:00Added an answer on May 26, 2026 at 1:33 am

    Instead of writing directly to files, save your bitmap to a MemoryStream and then save the contents of the stream to disk. This is an old, known issue and, frankly, I don’t remember all the details why this is so.

     MemoryStream mOutput = new MemoryStream();
     bmp.Save( mOutput, ImageFormat.Png );
     byte[] array = mOutput.ToArray();
    
     // do whatever you want with the byte[]
    

    In your case it could be either

    private void UploadImage(string uploadedImage)
    {
        // Convert Base64 String to byte[]
        byte[] imageBytes = Convert.FromBase64String(uploadedImage);
    
        string uploadPath = Server.MapPath("..\\uploads\\") + DateTime.Now.Ticks.ToString() + ".jpeg";
    
        // store the byte[] directly, without converting to Bitmap first 
        using ( FileStream fs = File.Create( uploadPath ) )
        using ( BinaryWriter bw = new BinaryWriter( fs ) )
           bw.Write( imageBytes );
    }    
    

    or

    private void UploadImage(string uploadedImage)
    {
        // Convert Base64 String to byte[]
        byte[] imageBytes = Convert.FromBase64String(uploadedImage);
        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
    
        System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)Image.FromStream(ms);
    
        string uploadPath = Server.MapPath("..\\uploads\\") + DateTime.Now.Ticks.ToString() + ".jpeg";
        ms.Close();
    
        // convert to image first and store it to disk
        using ( MemoryStream mOutput = new MemoryStream() )
        {  
            bitmap.Save( mOutput, System.Drawing.Imaging.ImageFormat.Jpeg);
            using ( FileStream fs = File.Create( uploadPath ) )
            using ( BinaryWriter bw = new BinaryWriter( fs ) )
                bw.Write( mOutput.ToArray() );
        }
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create an ASP.NET MVC web application which has extensible logic
I've written an ASP.NET 2.0 web service which is consumed by a web application
I am facing one problem. I have to create asp.net 4.0 web application which
I have created a Web Application in asp.net 2.0. which is working fine on
I create new ASP.NET web application that use SMTP to send message. The problem
Is it possible to create nested master pages in an ASP.NET Web Application projects
In VS2008, I go to File/New/Project, select ASP.NET Web Application and create a new
I need to create a web application using ASP.NET MVC, jQuery and web standards
I've a ASP.Net application which utilizes SQL Server Stored Procedures and Web Services using
I need to create an ASP.NET 2.0+ web application that allows the user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.