locked
Web api Push header before contnet RRS feed

  • Question

  • User-64729213 posted

    Hi,

    In my web api i have a file download controller. This controller will check a specific folder for file chunk and flush the chunks to the user. It will take some seconds to get the first chunk in the folder. I want to throw the response content header that is the file name before the first chunk but i cant. Is there a way to flush header first before content so that the user understand file download is in progress.

    Thanks,

    Subbiah K

    Wednesday, May 4, 2016 3:00 PM

Answers

  • User36583972 posted

    Hi subbiahkk,

    As far as I know, header and content are together in Response. The Web API doesn't "push" information. So, I think your current thinking is not feasible. You can try other ideas.

    1: You can immediately display file download is in progress when the user requests. When receive the file download finished message, you can display the file download finished.

    2: You can consider SignalR for this.

    SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available.

    You can refer to the following steps:

    *First you send a GET request to receive the size of the file you're about to download and store it in your client. In fact, you could utilise the Content-Length header here to avoid the extra GET.

    *Then download your file, while it's happening, your client can report the download progress by comparing how much of the file it has received against the full size of the file it got from the server

    You can learn About ASP.NET SignalR in the below link:

    http://www.asp.net/signalr

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 5, 2016 2:26 AM

All replies

  • User36583972 posted

    Hi subbiahkk,

    As far as I know, header and content are together in Response. The Web API doesn't "push" information. So, I think your current thinking is not feasible. You can try other ideas.

    1: You can immediately display file download is in progress when the user requests. When receive the file download finished message, you can display the file download finished.

    2: You can consider SignalR for this.

    SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available.

    You can refer to the following steps:

    *First you send a GET request to receive the size of the file you're about to download and store it in your client. In fact, you could utilise the Content-Length header here to avoid the extra GET.

    *Then download your file, while it's happening, your client can report the download progress by comparing how much of the file it has received against the full size of the file it got from the server

    You can learn About ASP.NET SignalR in the below link:

    http://www.asp.net/signalr

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 5, 2016 2:26 AM
  • User-64729213 posted

    Hi Yohann Lu,

    Thanks for your response. Planning to show some indicator from client end, as well as will try to understand SignalR also.

    Thanks Again,

    Subbiah K

    Thursday, May 5, 2016 1:22 PM