Tuesday, June 25, 2013

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


Controller action code.


public FileStreamResult Index()
{

    string aURL = "http://1.bp.blogspot.com/-reA6gMCM5CI/UN7YFauH12I/AAAAAAAAAd0/J6LLN3HV72E/s828/stuff%2Bcopycc.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 × +