Viewing large pdf files from SharePoint in browser anonymously(no login)

jawahar ks 1 Reputation point
2022-12-06T17:05:27.557+00:00

Hello,
I have a SharePoint online document library which contains large PDF documents which are more than 200mb.

I have a MVC application which will show these PDF documents from SharePoint. Currently in the code, I'm downloading the entire document in memory and opening in the browser.
This takes time to show even the first page as it need to download the entire file in the memory. I need to load these documents for users who do not have access to SharePoint.

This works well if I directly open the SharePoint file URL and it is streaming the files (loading the first few pages instantly). But this requires logging in to the SharePoint site.

My company policy doesnt allow me to generate the anonymous file URL.

I know there is an option to generate the temporary file download URL for the documents in SharePoint library using Graph API by passing some token.

Is there any other option similar to this available to show the document view page in the browser by passing the token?

Or Is there any other option available which can solve my problem?

Thanks in advance.

Thanks,
Jawahar

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,603 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,953 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 35,071 Reputation points Microsoft Vendor
    2022-12-07T06:09:53.26+00:00

    Hi @jawahar ks
    Per my research, I would recommend you to grant access using use SharePoint app only. Then you can get access token by the app only.
    Here is the document about SharePoint app only
    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs

    Please refer to the following steps to get an access token
    https://global-sharepoint.com/sharepoint-online/in-4-steps-access-sharepoint-online-data-using-postman-tool/

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

  2. jawahar ks 1 Reputation point
    2022-12-07T20:20:50.067+00:00

    Hi @RaytheonXie_MSFT ,

    Thanks for the answer. Using the SharePoint app with the token, I can perform other operations like accessing list, add/edit items.
    But is it possible to load document view URL with the token?

    Thanks,
    Jawahar


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.