0

I'm using Angular with ASP.NET core 3.0 and kind of new, I've a function that save pdf files in the Backend asp.net in a Folder "Resources\PdfFiles"

I got upload function to work fine, and it saves the files and it gives me the url of "Resources\PdfFiles" back, which is ok, but how do I display the pdf file from the FrontEnd, like is there any function, that I can retrieve the files from "Resources\PdfFiles"

I just wanted to create a button, when a user click on it, it displays the pdf

would you please help me out

2 Answers 2

0

The way to view PDF file is same with Image file.

You need change data:image/png to data:application/pdf

I have answer for display image file using Web API, you can refer at:

https://stackoverflow.com/a/55324972/4964569

[Route("{id:int}/image")]
    public async Task<dynamic> GetImage(int id)
    {
        var data = await this.designService.GetImageAsync(id);

        byte[] result = data.Data;

        return new { Image = result}
    }

In service add private sanitizer: DomSanitizer to constructor.

this.service.getImageThumbnail(id).subscribe(
  baseImage => {
    let objectURL = 'data:image/png;base64,' + baseImage.Image;

    this.thumbnail = this.sanitizer.bypassSecurityTrustUrl(objectURL);
  },
  error => (this.errorMessage = error)
);
Sign up to request clarification or add additional context in comments.

3 Comments

where you got designService from ?
you can defined yourself, in GetImageAsync() you read folder to get image content
doesn't the pdf saved in static wwwroot folder, so why can't i pull it from the folder.
0

If you have saved your file in wwwroot, just refer to your physical file in this way:

 window.open(
     '/Resources/PdfFiles/yourpdfname.jpg',
      '_blank',
    );

12 Comments

it's been saved in the wwwroot, still won't u work when I try to do it on the client side..
Have you added app.UseStaticFiles(); in your startup?
I did, and added your code to the client side, when I click on it, it opens, localhost:4200/wwwroot\resources\pdfFiles\names.pdf
which won't open
wwwroot shouldn't be in the address, your path should be like below:localhost:4200/resources/pdfFiles/names.pdf
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.