Communicating Progress Updates from C# to Angular 6 Using HttpPost

I'm building an Angular 6 application with a progress bar that displays the rendering and downloading progress of a PDF file as a percentage. Here's my Post call:

renderReport(renderObjectId: number): Observable<HttpEvent<Blob>> {
    return this.httpService.post('/render/report/' + renderObjectId, {
        observe: 'events',
        responseType: 'blob'
    });
}

The corresponding backend method looks like this:

[HttpPost]
[Route("report/{renderReportId}")]
[ResponseType(typeof(HttpResponseMessage))]
public HttpResponseMessage PrintReport(int renderReportId)
{
    var man = new RenderingManager();
    MemoryStream pdfFileStream = man.RenderReport(renderReportId);
    return CreatePdfDownload(pdfFileStream);
}

The RenderReport() method takes some time because it involves writing and validating XML. I want to be able to subscribe to updates from the backend in the frontend, such as "currently in step 5 of 12 in RenderReport()". Is there a way to achieve this, possibly by manually returning status updates after each method call within RenderReport?

Answer №1

If you have a time-consuming task that needs to be run when your API is called, consider running it asynchronously. Instead of waiting for the task to finish, return an Accepted (202) status code immediately along with a Location header. Users can then continuously poll this location to check the status of the task using a unique identifier stored in-memory. Once the task is complete, remember to delete this identifier to signal completion.

For more information, check out:

Learn about long-running operation polling at:

This method allows you to avoid waiting for the task to finish and instead keep track of updates by continuous polling.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Update Angular 10 ESRI Map Layers Without Reloading the Entire Map

Recently, I successfully developed an Esri Map using Angular 10 where users can toggle different map layers by selecting from a group button. The input for selecting layers is an array, for example: ['0', '1', '2'], with each ...

Discover the best way to showcase items within an arrayList using dual CSS styles!

I'm currently working on a project that involves an arrayList with two names: Bob and Steve. I have the requirement to display them in different colors, where Bob should be displayed in green and Steve in red. Component.CSS .Bob{ font-weight:bold; ...

Using Typescript for AngularJS bindings with ng.IComponentController

Currently, I am utilizing webpack alongside Babel and Typescript Presently, the controller in question is as follows: // HelloWorldController.ts class HelloWorldController implements ng.IComponentController { constructor(private $scope: ng.IScope) { } ...

Unable to break down the property 'desks' of '(0 , _react.useContext)(...)' due to its undefined nature

Trying to mock DeskContext to include desks and checkIfUserPresent when calling useContext is causing an error to occur: Cannot destructure property 'desks' of '(0 , _react.useContext)(...)' as it is undefined TypeError: Cannot destruct ...

The overall package size post transitioning to standalone versions and incorporating lazy loading

Initially, my app had a setup where each component had its own module and lazy-loading was implemented. This resulted in a main.js bundle size of 2mb. However, after converting to standalone components with lazy loading, the bundle size increased to 4mb. ...

How to retrieve data from a JSON file in Angular 2 using the http get

I am encountering an issue while trying to access a json file using http get. The error message I receive is as follows: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterable ...

Executing Oracle Package: ORA-06550 or ORA-06502

Whenever I attempt to execute a package on our Oracle database using either Oracle's .NET provider or Microsoft's Oracle provider, I encounter the following error message: {"ORA-06550: line 1, column 7:\nPLS-00221: 'BEGIN_TRANSACTION& ...

Configuring properties for an Ajax tabContainer

Building an Admin Panel using the Ajax tab container with 5 tapPanels, each containing a Panel from standard tools. Within each Panel is a GridView displaying added data. Additionally, there is an Add button located outside of the Ajax tabContainer. The is ...

In a situation where Typescript fails to provide enforcement, how can you effectively indicate that a function is not defined for specific value(s)?

If I were to utilize Typescript to create a function called mean that calculates the mean of an array of numbers, how should I handle the scenario where the array is empty? Enforcing that an array must be non-empty can be inconvenient, so what would be th ...

What is the most effective method for importing the "exceljs" library into an Angular project?

In my Angular 7 app, I am utilizing exceljs (https://www.npmjs.com/package/exceljs) to handle importing and exporting of Excel files. Currently, I have imported it using the following code snippet: import {Workbook} from "exceljs";. While it functions perf ...

How to import a child component in Angular 2 [v2.4.10] without declaring it in the

I am facing a dilemma with two components parent.component.ts @Component({ selector: 'my-element', template: ` <h4>{{title}}</h4> <child-element></child-element> //<-- I need to retrieve data from ...

Typescript Tooltip for eCharts

I'm working on customizing the tooltip in eChart v5.0.2 using Typescript, but I'm encountering an error related to the formatter that I can't seem to resolve. The error message regarding the function keyword is as follows: Type '(param ...

Retrieve a specific HTML fragment from an HTML document using the Html Agility Pack

Is there a way to extract an html "fragment" using the html agility pack from a full html document? In this case, I define an html "fragment" as all content enclosed within the <body> tags. For instance: Input Sample: <html> <head> ...

Issue with the functionality of Angular reactive custom validator inoperable

Recently, I created a simple validator that compares the values of two date form controls within a form group. The basic rule is that the maturityDate has to be greater than the valueDate, otherwise the form group should be marked as invalid. Here is how ...

How can I execute a StoredProcedure using JavaScript?

I have a form with an email field and label <asp:TableRow runat="server"> <asp:TableCell runat="server"> <asp:TextBox runat="server" ID="txtUserEmail" onfocusout="emailVerification()" CssClass="forTe ...

Tips on implementing computed properties in Vue.js while using TypeScript

There is a significant amount of documentation on how to utilize Vue.js with JavaScript, but very little information on using TypeScript. The question arises: how do you create computed properties in a vue component when working with TypeScript? According ...

Sharing information with child components in Angular

I am currently working with Angular and I have two child components that I need to pass data to. In the home template, my code looks like this: <div class="myCard"> <mat-card style="width: 500px;"> <mat-card-tit ...

What distinguishes injecting a provider in Angular2's @Component versus @Module?

When working with Angular2, it is possible to specify the providers in either a @Component element or in a @NgModule element. For example: @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: [&apos ...

Exploring the World of Angular6 with the Incredible Power of tinyMCE Editor

Hello, I'm looking to incorporate the tinyMCE editor into my Angular 6 application. I followed a thread that explains how to integrate it, but I ran into an issue where it says the domain is not registered. I would prefer to do this without requiring ...

The implementation of Typescript in Express does not rely on Middleware

I've encountered an issue with my Auth Middleware - it seems that the middleware isn't being called at all. Even when I intentionally throw an Error within the middleware function, nothing is printed out. For testing purposes, I only need to inv ...