The advantages of Blazor need to be understood as an overall application development ecosystem, including robust and easily understood package dependency management, reuse of existing. This article is only about "getting users to download content", which is a very limited scoped topic.īlazor is undoubtedly one of the strongest options for implementing SPAs for those who benefit from the development environment surrounding C# and C#. This article is not describing the whole of Blazor.
Javascript download link free#
If you know more efficiently implementation, please feel free to get in touch with me, and let's share the technic.Īre you saying that "Blazor is a pointless technology"!?
Javascript download link how to#
I showed you how to implement the "download file" feature in a Blazor app in this article.Īll of the sample code is published at the GitHub repository below. (source byte array is duplicated as another representation, again.) The base64 string is decoded to number array.(source byte array is duplicated, again.) The base64 string is copied from Blazor runtime to JavaScript runtime.(source byte array is duplicated as another representation.) source byte array is encoded to base64 string.However, please remember these implementations are very inefficient.īecause these implementations cause duplicating source byte array many times. īy using these implementations, we can make a byte array to downloadable.
The hack is, adding target="_top" attribute to the IJSRuntime JSRuntime. To avoid the interception of URL navigation by Blazor, we can use a hack. Method 2 - make tag with download attribute, and. In addtion, the download file name that is specified in download attribute is ignored. To be exact, if the content type of the linked file is not well known for the web browser, it will be started the download.īut even if this scenario, this behavior will also give us a bad experience, because the URL of the address bar will be changed from the URL of the current page to the URL of the file. Therefore, if the user clicks this tag, the user will see the picture file inside the browser window, downloading the file is not started. However, in this scenario, Blazor doesn't consider the download attribute! If there is no matching route URL, the URL navigation is passed through to the web browser. Please remind that the runtime of Blazor intercepts all of URL navigations, and transfer it to rendering a component which has a matching route URL. Unfortunately, this solution doesn't work as expected.