MarcoM
MarcoM

Reputation: 13

How can i call a Method from the Server project in Blazor Webassembly?

I have a Blazor Webassembly PWA Project called "QrReader.Client" and a Project called "QrReader.Server" which was generated after checking the checkbox "ASP.NET Core hosted". In my "QrReader.Client" Project i used a js library to read QR codes which works fine. Now i want to implement a solution which creates and writes a textfile to my FTP Server after a succesfull scan. I already have a "UploadToFtp()" method for that which works fine but its the first time im working with an API.

So where should my "UploadToFtp()" method be located and how can i call this method after a succesfull Qr scan from the javascript or razor? I don't feel like this method belongs to an API Controller...

Upvotes: 1

Views: 272

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273169

... a solution which creates and writes a textfile to my FTP Server after a succesfull scan.

Why would you use FTP? It's an old protocol and not supported in a Browser app.

The result of a scan can be Posted to your API (QrReader.Server) as Text or as a DTO.

If you need a starter, look at how FetchData.razor uses GetAsJsonAsync to get its forecasts. You will need PostAsJsonAsync to go in the other direction.

When you really need FTP you can then upload it from your Server with, FtpWebRequest.

Upvotes: 1

Related Questions