C# Response.WriteFile vs Response.TransmitFile filesize issues

前端 未结 2 524
南旧
南旧 2021-02-06 04:57

I have a 5Mb pdf on the server dowloading this file using a writeFile gives me a 15Mb download, where as the transmitfile gives the correct 5Mb filesize...

Is this due t

相关标签:
2条回答
  • 2021-02-06 05:26

    TransmitFile - Writes the specified file directly to an HTTP response output stream without buffering it in memory.

    WriteFile - Writes the specified file directly to an HTTP response output stream.

    I would say the difference occurs because Transmit file doesn't buffer it. Write file is using buffering (Afiak), basically temporarily holding the data before transmitting it, as such it cannot guess the accurate file size because its writing it in chunks.

    0 讨论(0)
  • 2021-02-06 05:34

    You can understand by following definition.

    Response.TransmitFile VS Response.WriteFile:

    • TransmitFile: This method sends the file to the client without loading it to the Application memory on the server. It is the ideal way to use it if the file size being download is large.

    • WriteFile: This method loads the file being download to the server's memory before sending it to the client. If the file size is large, you might the ASPNET worker process might get restarted.*

    Reference :- TransmitFile VS WriteFile

    0 讨论(0)
提交回复
热议问题