Tuesday, June 25, 2013

Download an Image from a given URL in ASP.NET MVC


Controller action code.


public FileStreamResult Index()
{

    string aURL = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjafp8BY_8P6NkZcQQLgJ7eCcjNfF7sg5fTWkNaNdsb8-LbP1Qo_ZeHPyw5TFafsxqZn7ycgjQliIUYP9N0GuNEEvxJ6i9DubxnsPc0bHl1Ngg1-DYKS0h8dLOfuXd9l2JjOcR1SsATwko/s828/stuff+copycc.jpg";
    Stream rtn = null;
    HttpWebRequest aRequest = (HttpWebRequest)WebRequest.Create(aURL);
    HttpWebResponse aResponse = (HttpWebResponse)aRequest.GetResponse();
    rtn = aResponse.GetResponseStream();
    return File(rtn, "image/jpeg", "Image_1");
}

No comments:
Write comments
Recommended Posts × +