Sharepoint Onedrive API word to pdf format download operation failed time out issue

Atachi ABL 0 Reputation points
2024-12-03T07:18:24.5833333+00:00

I am reaching out regarding an issue I am encountering while attempting to download a PDF file using the SharePoint REST API. Specifically, I am receiving a "Timeout" error when attempting to download a PDF file from the following endpoint:

URL: https://atachisystemssanjose-my.sharepoint.com/_api/v2.0/me/drive/items/{itemId}/content?format=pdf

Issue Summary:

I am making a GET request to the SharePoint API to retrieve a file in PDF format. However, I am encountering a timeout error when the request is executed. I have attempted to configure timeouts in both Java and Python, as well as in my client-side JavaScript, but the issue persists. Below is the relevant code snippet I am using in JavaScript for this request.

var url = "https://atachisystemssanjose-my.sharepoint.com/_api/v2.0/me/drive/items/"  + id + "/content?format=pdf";
var method = 'GET';
var xhr = createCORSRequest(method, url);
xhr.onload = function(response) {

if (response.target.status == 200) {

    var webUrl = response.originalTarget.responseURL;

} else {

    alert("Please Refresh the Page (or) Check CORS Plugin Enabled");

}
};

xhr.onerror = function() {

sql
// Error handling logic
};

xhr.setRequestHeader('Authorization', 'Bearer ' + GlabalAccess_token);

xhr.setRequestHeader('Content-Type', 'application/json');

xhr.setRequestHeader('Prefer', 'respond-async');

xhr.setRequestHeader('Access-Control-Allow-Origin', '*');

xhr.send();


  

Steps Taken to Troubleshoot:

  1. Timeout Configuration: I have set appropriate timeouts in Java, Python, and JavaScript, but the request still times out.
  2. CORS Issues: I have ensured that the CORS plugin is enabled, and the necessary headers (such as Access-Control-Allow-Origin) are set correctly.
  3. Token Authorization: I am using a valid access token for authentication.
  4. API Documentation: I have consulted multiple online resources and Microsoft documentation but have been unable to resolve the issue.

Request:

  • Could you kindly review the situation and provide guidance on resolving this timeout issue when accessing the SharePoint API endpoint?
  • Are there any specific configurations or limits that may be causing this timeout?
  • If there are any best practices for making this request more reliable, I would greatly appreciate your input Steps Taken to Troubleshoot:
    • Timeout Configuration: I have set appropriate timeouts in Java, Python, and JavaScript, but the request still times out.
    • CORS Issues: I have ensured that the CORS plugin is enabled, and the necessary headers (such as Access-Control-Allow-Origin) are set correctly.
    • Token Authorization: I am using a valid access token for authentication.
    • API Documentation: I have consulted multiple online resources and Microsoft documentation but have been unable to resolve the issue.
Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | OneDrive | For business | Windows
Microsoft 365 and Office | Word | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

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.