Link to home
Start Free TrialLog in
Avatar of Tricky1974
Tricky1974

asked on

Asp.net FileUpload limited to only images

Hello,

I used the solution to this question:

https://www.experts-exchange.com/questions/24686152/How-do-I-allow-only-images-using-the-FileUpload-control.html

to solve this problem; and I may have assigned points too soon as I've just noticed that the image doesn't load properly when received in the email.  Something during the process of checking is causing problems.

Any ideas would be much appreciated!

Thanks
Avatar of Kumaraswamy R
Kumaraswamy R
Flag of India image

Hi


Pl see the URL, It will give Some Inputs

http://forums.asp.net/p/1051895/2171502.aspx
Avatar of Tricky1974
Tricky1974

ASKER

Yeah, I had seen that.  A little way down the page someone on there said:

"One problem with peeking into the stream is sometimes you can get errors with uploading the file,  i have found that i actually have to dump the stream and re-upload the whole thing from the beginning after peeking at the first few bytes, if not sometimes the images does not re-assemble itself"

It says to dump the stream and reupload from the beginning - How would I go about doing this?
Hi

You can use BinaryRead to read from request body:

Request.BinaryRead

Or you could get a reference to input Stream object with:

Request.InputStreamThen you could use CopyStream:

using (FileStream fs = new FileStream(...))    
CopyStream(fs, Request.InputStream);
Hi Tricky1974,

I was the one who gave you the original solution, so perhaps it is good to help you further? ou way you have problems, is that about saving the stream after you tried to check the stream?

You shouldn't try to download the stream to a file, because that would defeat the purpose of checking the file. Basically, I can think of two methods here:

1. Use a MemoryStream, load the data in there, use that subsequently for checking and saving
2. Use the current approach and store the file from the img object. This is also the saver way, because you can pose other restrictions: dimensions, types, color depths, whatever, on the image. You can use the SaveAs method to store the image.

-- Abel --
ASKER CERTIFIED SOLUTION
Avatar of kumar754
kumar754
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial