flickr images over https

Topics: Developer Forum, User Forum
Oct 19, 2009 at 3:09 PM

Hi everyone,

this is more of an enquiry into if anyone out there has loaded images using a handler? I have tried since 8 30 this morning and its now 4 pm and I have gracefully given up on trying to achieve this. The dreaded unsecure items cannot be overcome so I am deleting the flickr widget from my site.

Amongst everything tried includes

HttpWebResponse response = (HTTPwebResponse)WebRequest.Create("http://farm4.static.flickr.com/3434/3969021243_8ef591af9e_s.jpg");

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    if ((request.HaveResponse) && (response.StatusCode == HttpStatusCode.OK))
                    {
                        using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                        {
                            //output image bytes as image
                        }
                    }
                }

ALSO

System.Net.WebClient wc = new System.Net.WebClient();

wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)");

System.IO.Stream s = wc.OpenRead("http://farm4.static.flickr.com/3434/3969021243_8ef591af9e_s.jpg");
System.Drawing.Image img = System.Drawing.Bitmap.FromStream(s);

NOTHING SEEMS TO WORK!!??????

 

OH and yes I have and can use the api to get the xml and json and fill with html which displays and scrolls the images etc... Its just that once the page loads with img src=http://.. i get the error of onsecure items.

 

Coordinator
Oct 19, 2009 at 3:31 PM

Firstly, why is your site required to be HTTPS? It sounds to me like you might be making a commercial site of some description and therefore I would ask you to consider carefully if you are following the Flickr terms of service.

Secondly, can you give me some indication as to what you mean when you say the above 'are not working'. What do they do exactly? How are you sending the stream back to the browser once you have it. Both of the examples you give above should work fine as far as I can see from the code you have listed.

Sam

Oct 27, 2009 at 2:23 PM

Sorry I'll re-iterate, its a student secure portal. It uses windows authentication via forms and SSL so i cannot give you a working example. If you are a c# coder you will see that the above code could be used to server images. e.g img src=imahgehandler.ashx?url=flickr.....img Now the hanlder can be anything from ascx, aspx, etc. the reasong for ashx handler is no page lifecyles etc.

long story short try the code and see if it works for you? might be a proxy issue on my network but i doubt it. Theres no stream because theres no response from the flikcr servers. if there was bufferoutput would show the image nicely.

Coordinator
Oct 27, 2009 at 2:56 PM

It was hard for me to convert what you had written above into a working example as you weren't showing how you were writing it out again. The following works fine for me:

 

    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = System.Net.Mime.MediaTypeNames.Image.Jpeg;

        System.Net.WebClient wc = new System.Net.WebClient();
        System.IO.Stream inputStream = wc.OpenRead("http://farm4.static.flickr.com/3434/3969021243_8ef591af9e_s.jpg");

        System.IO.Stream outputStream = context.Response.OutputStream;
        
        byte[] buffer = new byte[4096];
        int read = inputStream.Read(buffer, 0, buffer.Length);
        while( read > 0 )
        {
            outputStream.Write(buffer, 0, read);
            read = inputStream.Read(buffer, 0, buffer.Length);
        }
        inputStream.Close();
    }

Nov 18, 2009 at 1:46 PM
Edited Nov 18, 2009 at 1:49 PM

wc.Proxy = new WebProxy(ConfigurationManager.AppSettings["over18Proxy"].ToString());

You are absolutely right it worked fine from home until i icluded the line above for our network.

Thanks for taking the time, much appreciated.