I have a MVC controller which is returning a File result as follows
<pre>
public ActionResult GetPdf(string id)
{
string fileName = Server.MapPath("Somepdf.pdf");
FileInfo info = new FileInfo(fileName);
return File(info.OpenRead(), "application/pdf");
}
</pre>
This is read by an iOS app and this works fine.
But now I want to change this to stream the file from Amazon S3. I can get the stream from S3 easily but no matter what I return in the method, the iOS app does not like it.
<pre>
Stream pdfFrom = S3Interface.getstream("Pdfs/somepdf.pdf");
return File(pdfFrom, "application/pdf", "somepdfname.pdf");
</pre>
Ive tried numerous ways but cant seem to get the result to be valid.
I though I was close with this post by changing the result to a byte[] but still no joy as this doesnt seem to return all the bytes. Returning a stream from File.OpenRead()
System.IO.MemoryStream data = new System.IO.MemoryStream();
System.IO.Stream str = S3Interface.getstream("Pdfs/somepdf.pdf");
str.CopyTo(data);
data.Seek(0, SeekOrigin.Begin);
byte[] buf = new byte[data.Length];
data.Read(buf, 0, buf.Length);
return data.ToArray();
What I basically need is the equivalent to File.OpenRead but for a Stream.
Any advice appreciated