- #Javascript download file from url on click how to#
- #Javascript download file from url on click download#
This article is not describing the whole of Blazor. 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 file from url on click 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.
#Javascript download file from url on click download#
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.