Base solution for your next web application
Open Closed

Streaming File back to client as response #898


User avatar
0
paul lee created

Hi all,

Does anyone knows or have links to samples or tutorials about how to send files to client from the ApplicationServices?

Do I just sent the encoded byte array in an OutputDTO?

Thanks.


3 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Use regular Web API Controller or MVC Controller for it. Do not use app service since web streaming is a web stuff and should be in web layer.

  • User Avatar
    0
    paul lee created

    After some reading up on SO, I now understand that sending the file as a response of an ajax request is not possible. So I now want to try something like this:

    1. When the user wants to export some data to PDF, I use ApplicationService to Enqueue the document generation job in Hangfire. I am using SQL Storage for jobs.

    2. Inside the Background Job it will retrieve all the data (job control and related data from DB) then go off and generate the document. Finally it saves the file in a folder on the server.

    3. There should be something to keep polling the Job status(but I am not sure what?), when the job status changed to READY, it then sends a SignalR message to client (download URL inside the message payload)

    4. When the client received the message, it will trigger a File Download action to download the file from server.

    What I have tried now:

    1. I have the ApplicationService successfully enqueued job in both local and remote Hangfire server, I have verified this with the use of Hangfire dashboard

    2. I have also have the Background job to successfully generate, store the file to a specific folder and updated the job status to READY in DB. I have verified this by running sql queries to check the data records.

    3. I am stuck on this point, I am not sure will the polling of job status be done in the Hub or using another recurring job or should the Hangfire Job asks the Hub to send a message to the specific user at the end of the Background job execution?

    4. I have done a MVC controller with FileStreamActionResult ready for accepting the download requests from the clients.

    So what am I missing?

    Thanks.

  • User Avatar
    0
    djrot created

    Hi...

    Is there a method similar to Response.Redirect that will send variables to the destination page other than using a query string or the post method???