What is the fastest way to stream images from FILESTREAM to SQL to a browser?

I have images stored in my database in FILESTREAM, and I'm trying to figure out what the best solution is to return this image to a web browser.

If I myself managed files in the file system, the fastest way would be:

Response.TransmitFile(pathToFile);

This does not load the file into memory before transferring it back to the client (as far as I know), and, as such, is nice and fast.

I am currently using Linq for SQL to get FILESTREAM. This provides FILESTREAM as a binary.

So far, this pretty ugly way to do this is:

Response.WriteBinary(fileStreamBinary.ToArray());

Is it better for me not to worry with Linq to SQL and do something more directly?

, FILESTREAM . , , " "!

+5
3

, ( ) .

, Response.BufferOutput false, - true.

Linq to SQL - ?

, . ( ).

, FILESTREAM

, . , . , 1 , , .

Sql Server 2012 , FileTables, FileStream. , , , FileTable ( , Filestream , ). , Response.TransmitFile(...), sql Filestream.

+1

?

byte[] buffer = new byte[bufferSize];
int nBytes;
while((nBytes = fileStreamBinary.Read(buffer, 0, bufferSize) != 0)
{
    Response.OutputStream.Write(buffer, 0, nBytes);
}

,

+1

, , . , / , , .

( Pdf: s) Blob WCF ( ) → ()

, , , , - .

Response.Clear();
Response.ContentType = "application/pdf";
Response.Buffer = false;

var buffer = new byte[BufferSize];
int bytesRead;
while ((bytesRead = inputStream.Read(buffer, 0, BufferSize)) != 0)
{
     if (!Response.IsClientConnected)
          break;

     Response.OutputStream.Write(buffer, 0, bytesRead);
     Response.Flush();
}
0

All Articles