How to view file in viewer without downloading and saving to server file system

We are using GroupDocs 21.4.1 with the angular client in a .NET MVC application. Our implementation is as follows:

  1. UI contains links to documents
  2. User clicks on document link (viewer/Index?file=[filePath])
  3. The document is downloaded to the location in the above [filePath]
  4. GroupDocs generates the html files and resources and displays in the viewer

However, we now have a requirement that the files cannot be downloaded and stored on the server. They must be loaded directly into the viewer. Is this possible with the updated GroupDocs API and angular client? I see docs related to Loading from URL and Loading from FileStream, but the code seems different from what is provided in the .NET expample project. Also, will the “file” url parameter still work or does this necessarily look for the file in the local file system? Are there any docs that list what other parameters are available?

In short, I need users to be able to click a link and view a document in the angular viewer without that document having to be stored on the server.

Any help you can provide is much appreciated!

@bennett.foster

Welcome to GroupDocs Forum!

As you’ve already noted GroupDocs.Viewer generates HTML files on the server so the file has to be downloaded. On the first request, you can download a file into memory (MemoryStream) and generate HTML for all of the pages and possibly PDF in case you’re printing PDF. All this logic should be added to your ViewerApiController file LoadDocumentDescription method.
In case you’re using MVC Demo from GitHub you can set preloadPageCount: 0 in the configuration file to render all the pages but you’ll also need to update logic so the file is not stored on the local disk.

As a demonstration please download MvcMinimal App that shows how can you render a file from URL without storing it on a local disk. Run the app and add a query string parameter with the URL to your file e.g. https://localhost:44389/?file=https://docs.groupdocs.com/viewer/net/images/home.png.

Unfortunately, there is no documentation for the Angular UI except its source code. There is one more parameter that is supported court of the box - url. In case you specify this parameter the UploadDocument API method will be called. But again it is expected that you download and store the file or render it completely in that method.

Feel free to contact us in case you have any questions.

Thanks for your quick response! This is helpful. However, I see in the example you give (https://localhost:44389/?file=https://docs.groupdocs.com/viewer/net/images/home.png) the value of the file parameter is a URL that points to a physical file location. But the files that I am working with are coming from a database where they are store as a byte array. So I have an API endpoint that returns a FileContentResult to the server. Ideally I don’t want to store the physical file anywhere, I’d like to load it to the viewer directly as a byte array. Is this possible?

@bennett.foster

I’m sorry for the delayed response. Sure, instead of downloading a file from the URL you can just pass any identifier as a value of ?file= query string parameter e.g. ID of your file ?file=my-id. In the API controller you just select the data from DB instead of downloading a file from URL.

Thank you, this has helped tremendously. I ran into an issue where the JsonProperty attributes in the DocumentDescriptionResponse class of the MvcMinimalApp project were not working, so the pages were unable to load. But I’ve got that worked out now.

Thank you for all your help!

One last question: Given this implementation, what would be the best steps to take to optimize performance. Our client has complained about load times for documents, and I suspect it will be the same or slower now that we can’t cache any files on the server. Do you have any suggestions?

Thanks!

@bennett.foster

Thank you for your feedback!

You can render a file faster using threads, as a simple example, you can render a file with 20 pages in a single thread or use two threads where each thread will render 10 pages. The rendering will complete faster but you’ll pay with the memory and CPU time.

The file can be rendered partially e.g. first N pages then when a user is scrolling down next N pages. In this case, you’ll have to download a file each time you need to render the next N pages. It can be a good solution for small files but the user will have to wait while the next chunk is rendering.