bojack1579
bojack1579

Reputation: 13

Show(or Open) pdf file in page from Azure File Storage

Have an issue that can't show pdf file in the page or open without downloading this file in the browser.

I'm using .net core 2.1 and Azure File Storage. When I get the file from storage, I have CloudFile object and after that, I'm tried to read this file using FileStream and send to page. Or somehow open this file in the browser without download it. File storage is in private mode, so I can't get the file by direct link, so need only read the file and after send it to page/browser to show.

Can you please help with this issue, because can't find a solution that will work for CloudFiles in pdf format to read them? Maybe some free library for it. Could be info from pdf insert to razor view?

Thanks!

Upvotes: 0

Views: 1280

Answers (2)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29950

Actually, you can directly use stream without using byte array, less code:

var stream = await file.OpenReadAsync();
return File(stream, "application/pdf");

Upvotes: 1

bojack1579
bojack1579

Reputation: 13

I'm using next and it's work: Here "file" - is "CloudFile" object.

var stream = await file.OpenReadAsync();

byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, Convert.ToInt32(stream.Length));

return File(bytes, "application/pdf");

Upvotes: 0

Related Questions