I need to show an image (thumbnail) on a view page using a controller / action. (for example: / Image / Thumbnail) I can send an image file that is stored locally by calling a method in the controller.
// sample code public FileResult Thumbnail() { // get image Stream outFile = System.IO.File.Open("c:\\test.jpg", FileMode.Open); // send image return File(outFile, "image/jpeg"); }
How can I send an image file that is stored in Amazon S3?
Can I use the Amazon S3 URL in the above method to return an image? → http://bucketname.s3.amazonaws.com/test.jpg?AWSAccessKeyId=AKIAIDLH65EJ6LSWERDF&Expires=1266497098&Signature=lopDEDErjNLy2uz6X6QCNlIjkpB0%3D
thank
:
public ActionResult Thumbnail() { return Redirect("http://domain.com/test.jpg"); }
URL- , . , URL , - <img> src:
<img>
<img src="<%= Url.Action("Thumbnail", "ControllerName") %>" />
WebClient:
WebClient wClient = new WebClient(); Stream stream = new MemoryStream(wClient.DownloadData('http://....jpg')); return File(stream, "image/jpg");
you can create a web request to receive a stream
public FileResult Thumbnail() { // get image HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(@"http://bucketname.s3.amazonaws.com/test.jpg?AWSAccessKeyId=AKIAIDLH65EJ6LSWERDF&Expires=1266497098&Signature=lopDEDErjNLy2uz6X6QCNlIjkpB0%3D"); WebResponse myResp = myReq.GetResponse(); Stream outFile = myResp.GetResponseStream(); // send image return File(outFile, "image/jpeg"); }