Not Able To Download File Content In Microsoft Office 365 Account

Casepoint Developer 66 Reputation points
2021-07-26T12:22:22.58+00:00

Hi,

I am trying to use this method to access file data.
API: GET/ https://graph.microsoft.com/v1.0/me/drive/items/{item-id}/content

I am using above API to get the Download URL and Location of the File for Office 365 account. When I am using the Download URL directly in the browser then the file is being downloaded easily, but when I am trying it through the code then it is throwing an exception as follows

Message: The underlying connection was closed: An unexpected error occurred on a send.
Inner Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

The code snippet of the code is as follows:
117952-untitled.png

Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. JosephXu-MSFT 531 Reputation points
    2021-07-27T07:53:40.653+00:00

    Hi @Casepoint Developer . I've tried your code, there is no problem. I can download one jpg from my onedrive.
    You need to check these two settings:

    1. You can decode JWT Tokens here to verify the permissions of your token. The "scp" property should contains Files.Read Files.Read.All Files.ReadWrite Files.ReadWrite.All. You should use postman to verify that you can access the jpg in your onedrive via the access_token. As follows show, I can access my jpg in my onedrive:
      118212-image.png
    2. Is your access token delegated type, if not, you should refer to this document Get access on behalf of a user:
      118200-image.png
    0 comments No comments

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.