This is a migrated thread and some comments may be shown as answers.

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

0 Answers 54 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
JohnH
Top achievements
Rank 1
JohnH asked on 17 Oct 2012, 05:48 PM
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;
    }
}
  

No answers yet. Maybe you can help?

Tags
AsyncUpload
Asked by
JohnH
Top achievements
Rank 1
Share this question
or