Open Closed

How to call Controller directly from Blazor Server page #3115


User avatar
0
alin.andersen created

Hey,

so we need to upload a file from our Blazor Server App to the Backend.

Problem is we can't use the IFileForm in our ApplicationService because it depends on Microsoft.AspNetCore.Http and we do not want to include this dependency on all our clients (we have other mobile clients beside the Blazor Service client).

So the only way we can upload a file properly is to call the controller directly from our Blazor Server App with the file.

For that to work we need the URL of the Remote Service and the Bearer Access Token.

How can we inject these two required information into the Blazor Server page in order to create our own HttpClient and make the call with the file attached?

Should we retrieve the URL for the remote service by using IConfiguration? Is this the best way to do it?

Thanks!

  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC)

Update:

I also tried to inject IHttpClientFactory hoping the Bearer Access Token would be set. But all headers are empty.


6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Problem is we can't use the IFileForm in our ApplicationService

    hi

    Use IRemoteStreamContent in app service.

    https://docs.abp.io/en/abp/latest/Application-Services#working-with-streams

  • User Avatar
    0
    alin.andersen created

    Ah thank you very much! We will try using the IRemoteStreamContent interface.

    Just out of curiosity: Is it possible to retrieve the Bearer Access token? Or is it not possible due to security requirements.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Is it possible to retrieve the Bearer Access token? Or is it not possible due to security requirements.

    Can you show a case?

  • User Avatar
    0
    alin.andersen created

    Is it possible to retrieve the Bearer Access token? Or is it not possible due to security requirements.

    Can you show a case?

    Why do you need a showcase? Is it possible to retrieve the Bearer Access token or not? It is a yes or no answer. If it is not possible, then my question is why? The client should anyway have access to the Bearer Access token.

    As an example, what if I need to implement something very specific in the Blazor Server client where I have to interact with a controller directly.

    Thanks for the help!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The framework will automatically get and send the bearer token when you inject the Application Service in Blazor.

    So use IRemoteStreamContent in your app service and inject it in your blazor

  • User Avatar
    0
    alin.andersen created

    Ok thanks for the clarification! So this is not possible and this is a limitation by ABP.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38