Streaming an Image with C#/Firefox

Log in to stop seeing adverts

Status
Not open for further replies.

Matt_B

Well-Known Member
Roit, let's try this on for size.

I have a dynamic image resizing class in my project, that will take the uploaded image and create and save thumbnail versions.

When required these are then loaded using a FileStream method (below) and streamed to a page.

I can access the image using an <img src='path to script' /> and it works fine, the problem is, if in Firefox I right click and select View Image I get the attached screen shot. If I type the same URL into IE7 or IE6 it works fine and displays the thumbnail.

I assume this is something to do with the mimetype or encoding, but as far as I am aware they are correct, any idea?

screenshot
image error.jpg

code block

Code:
FileStream oStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                long FileSize;
                FileSize = oStream.Length;
                byte[] getContent = new byte[(int)FileSize];
                oStream.Read(getContent, 0, (int)oStream.Length);
                oStream.Close();

HttpContext.Response.Clear();
                HttpContext.Response.Buffer = true;

                HttpContext.Response.ContentType = "image/jpeg";

                HttpContext.Response.BinaryWrite(getContent);

This is now driving me mad for such a small issue.
 
Edit: Fecking w*nk tw*t, noob error. I forgot the Response.End() at the end, it was interpreting a single white space in the page as HTML content (correctly I suppose) and so not rendering the image. Close the thread.
 
Status
Not open for further replies.
Log in to stop seeing adverts

Championship

P Pld Pts
1Leicester4697
2Ipswich4696
3Leeds Utd4690
4Southampton4687
5West Brom4675
6Norwich City4673
7Hull City4670
8Middlesbro4669
9Coventry City4664
10Preston 4663
11Bristol City4662
12Cardiff City4662
13Millwall4659
14Swansea City4657
15Watford4656
16Sunderland4656
17Stoke City4656
18QPR4656
19Blackburn 4653
20Sheffield W4653
21Plymouth 4651
22Birmingham4650
23Huddersfield4645
24Rotherham Utd4627

Latest posts

Top