How to wait for filename from javascript saving pdf file in blazor wasm?

229 Views Asked by At

I use this code from syncfusion: https://help.syncfusion.com/file-formats/pdf/create-pdf-document-in-blazor#steps-to-create-pdf-document-in-blazor-client-side-application there is function ExportToPdf. How inside this ExportToPdf can code wait for user choosen filename and continue after saving file on disk? I want to disable button to not allow it to press again until pdf file is completely saved. And how to get filename user had choosen?

Also there is this extension method: public static class FileUtil

{
    public static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
       => js.InvokeAsync<object>(
           "saveAsFile",
           filename,
           Convert.ToBase64String(data));
}

Can someone explain to me how this lambda => expression works here?

1

There are 1 best solutions below

0
On

What that is doing is calling the saveAsFile function defined on the window object in the javascript file. It passes two inputs to the function. One is the filename and the other is the contents of the file in base64 encoded format. The javascript code in the browser then downloads those bytes to the specified filename.