Question

I am trying to use swfupload to upload file to the server. The photo upload worked perfectly fine on the development machine but when i tried to check it on production server. there was 500 internal server error. Checking the exception details the

             `Stack trace:    at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
   at System.Drawing.Image.Save(String filename, ImageFormat format)
   at ImageryDataAccess.SaveFullSizeImage(Byte[] ImageData)
   at ImageryDataAccess.SaveUserImage(Byte[] ImageData, Guid UserId)
   at Photos.Page_Load(Object sender, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) `

showed this details. I checked the function save fullsizeimage there seemed to be only one suspect and that was

         string fileName=ImageName.ToString() + ".JPEG";
    string App_datapath = HttpContext.Current.Server.MapPath("~/App_Data/setP");
    bmp.Save(App_datapath+"/" +fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

This code works fine on dev server but not on production. What I am not sure what I am going wrong here. / is my only guess to be something a problem because the microsoft use\ for directory paths. but again why then it would work on dev server. If any one can resolve the issue..

Was it helpful?

Solution

The problem is you're trying to save to the App_Data folder - this folder is only available to actual code. You cannot write to it by default, you also cannot output its contents to your website.

The App_Data is specifically meant for Data only - such as XML & Database files - see here for more info: MSDN App_Data folder

So, even if you managed to save a file into app_data you would not be able to display it - you would receive an unauthorized access error message.

To fix, change this:

HttpContext.Current.Server.MapPath("~/App_Data/setP")

to something like this

HttpContext.Current.Server.MapPath("~/uploadImages/setP")

Essentially give yourself a different folder to upload to.

Update

Following from the comments it seems you are getting the A Generic error occurred in GDI+..... message. This is more often than not due to write permissions on the folder you're trying to save to is not set. Change them to enable write and you're good to go. Again though, it's best to not save them there unless you really must..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top