Viewer-api customize for stream usage and not storage

Hello, I want to implement groupdocs viewer. I download the sample .Net Core project.
I want to modify this project only I need to view a document when endpoint calls. And show that document only.

  • I have file on stream.
  • I dont want to download and put it on /storage folder.

In example .Net Core demo project in program.cs file is there a way to only set like comment below
image.png (10.3 KB)

My usage of viewer is like Im going to host this example viewer project standole. And display from <‘iframe’> in my project. So in my project its only open modal and show viewer in iframe and render only one document per time. Then its closing the viewer. I want to use viewer search and other download tools as well. So I dont want only to show document content.
groupdocs2.PNG (8.0 KB)

If I can complete this my company will buy this product for our usage.

@AlperenCinkaya

You can pass a file ID or path using a query string parameter e.g. ?file=invoice.pdf. You have to implement and register storage and if needed file type resolver

// ConfigureServices
services.AddTransient<IFileStorage, MyFileStorage>();
services.AddTransient<IFileTypeResolver, MyFileTypeResolver>();

// Implementation

 class MyFileStorage : IFileStorage
 {
     public Task<IEnumerable<FileSystemEntry>> ListDirsAndFilesAsync(string dirPath)
     {
         throw new NotImplementedException();   
     } 
     public Task<byte[]> ReadFileAsync(string filePath)
     {
         return File.ReadAllBytesAsync("./Storage/sample.docx");
     } 
     public Task<string> WriteFileAsync(string fileName, byte[] bytes, bool rewrite)
     {
         throw new NotImplementedException();
     }
 } 

 class MyFileTypeResolver : IFileTypeResolver
 {
     public Task<FileType> ResolveFileTypeAsync(string filePath)
     {
         // resolve file type by file path
         return Task.FromResult<FileType>(FileType.DOCX);
     }
 }

See this sample application for more details.

Let us know if you have any questions.

1 Like

Hello, thank you very much. I modified the project you send me and now its working. I override the ReadFileAsync for downloading file stream from my server and get byte[] to view.

groupDocs5.PNG (57.3 KB)

But I want to keep download button functionality and remove the DisableFileDownload() from config.
But problem is when I click download its getting like from (string filePath) which in my case its encoded Id fields. And not real file name. So I need to dynamically set fileName.
How can I override that in startup?

groupDocs6.PNG (3.6 KB)

@AlperenCinkaya

I’ve added support for setting the filename when downloading a file. The solution is similar to the one shared above.

 services.AddTransient<IFileNameResolver, MyFileInfoResolver>();

 //...

 class MyFileInfoResolver : IFileNameResolver
 {
     public Task<string> ResolveFileNameAsync(string filePath)
     {
         return Task.FromResult<string>("my-file-name.docx");
     }
 }

You have to use the latest package versions and .NET 6 or above as a target framework as shown in the sample app.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): VIEWERNET-4238

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.