6

I got a hard time with the Image.FromStream method in my website. The code below works perfect on my computer. But when I uploaded it to the test server, it always gives me "Parameter not valid" exception.

if (!afuImageFile.IsUploading && afuImageFile.HasFile)
{
    System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent);
}

the afuImageFile is an AsynFileUploader control in Ajax Tool Kits. afuImageFile.FileContent is a HttpInputStream. I guess I need to add some permission to some folder. Can anyone help me?

Abhishek
  • 6,912
  • 14
  • 59
  • 85
Leon.S
  • 61
  • 1
  • 1
  • 3
  • Sounds like a similar problem to this question. http://stackoverflow.com/questions/1614773/image-fromstreampostedfile-inputstream-fails-parameter-is-not-valid-async – NewfrontSolutions Nov 09 '15 at 13:59

1 Answers1

2

Please ensure that your FileContent stream as its position set to 0.

Otherwise, you might want to deactivate image validation by changing the call from:

System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent);

to:

System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent, true, false);

See Image.FromStream to check on the other overloads.

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107