Download documents from the Filesystem webserver

testing this on local machine becomes hard .
image

If you use the location properties to build the URL it shouldn't be hard to test on a local machine as the final URL will match the current protocol, host and port.

Hello @korchev
I tried your code as suggested in this thread and it all appears to work great however if the controller requires authorization the link control does not appear to pass the authentication. I added a button that calls Invoke and that appears to pass the authentication although not able to view the document.
1 - no authorize
2021-02-07_23-22-22
2 - authorize added to controller
2021-02-07_23-23-32
3 - link no longer works
2021-02-07_23-43-10
4 - although calling invoke does but cannot view file
2021-02-07_23-26-49

Any ideas?

Indeed one cannot pass HTTP headers (such as Authorization) via links. Alternatevely one cannot download a file via XMLHTTP request (which is what is used to invoke server methods).

I think @mcanavar implemented a working solution in the end. Maybe he will be willing to share the implementation with you.

1 Like

Hi,

The solution lies in that the documentation provided by Radzen (online) about this topic is not up to date with the angular version and needs some changes to work with the current used version in Radzen.

1.custom method
ASP.Net Core method for the conversion of the needed files from a network share on the server ([\server\share](file://server/share/)) to Blob. ( like the one you shared, but with the difference that it is a async task

image

  1. custom method return
    Difference on the returned File is that it is from a MemoryStream derived from the FileStream with CopyToAsync method and setting the Position to 0.

image

This method is called by an custom Angular (downloadpage.component.ts) method. ( like the one in the Radzen documentation )

Difference is that before using a “map” it needed a “pipe” and had to add import {map } from ‘rxjs/operators”

I have used a "button" in a DataGrid component and used its Click event to call the angular page method .(like the documentation ).

Could not get it to work with a "link" component.

So : Radzen calls (invokes) the method in the page.ts , that calls the backend api to get the "Blob" "MemoryStream" of the file by providing the "ID" and the "Name" of the document . In my case all documents have a enry in the database , the document record contains the document name and "relative" location on the fileserver with an unique document ID.

Leaving the Authorize decoration inplace to handle security.

image

I hope you can get it to work .

1 Like

Thanks @mcanavar for your detailed solution.
I will check out your solution in test app and report back.

Thanks, @korchev, @mcanavar
The code seems to work although I have only done limited testing with Chrome.
The only minor issue I encountered is the original server-generated error is not being returned correctly. The correct error is returned to the client but then gets overwritten with a different error relating to blob.
Have posted a demo video here

1 Like