Temp file read intermittently fails after call to base.Process()

1 posts, 0 answers
  1. JohnH
    JohnH avatar
    1 posts
    Member since:
    Oct 2012

    Posted 17 Oct 2012 Link to this post

    I'm working with a simple handler derived from AsyncUpload handler, whose entire code is below. In this code, the attempt to read the temp file created by the call to base.Process() as an image fails intermittently. When this fails, the file exists, the file stream can be opened, but the FileStream.Length is 0. Is there any way to work around this? I would expect the temp file to be accessible after the call to base.Process(). If it helps, this appears to only happen after I have already uploaded a file within the last few minutes.

    public class MyAsyncImageUpload : AsyncUploadHandler
        protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
            var result =base.Process(file, context, configuration, tempFileName);
            int imageWidth = 0;
            int imageHeight = 0;
            var imageExists = File.Exists(context.Server.MapPath("~/App_Data/RadUploadTemp" + "/" + tempFileName));
            using (var fs = new FileStream(context.Server.MapPath("~/App_Data/RadUploadTemp" + "/" + tempFileName), FileMode.Open, FileAccess.Read))
                var imageByteSize = fs.Length;
                using (var image = Image.FromStream(fs))
                    imageWidth = image.Size.Width;
                    imageHeight = image.Size.Height;
               return result;
Back to Top