how download file from one drive using java

Amol Harde 25 Reputation points
2023-03-09T05:14:30.81+00:00

Hi All,

Want to get file id and file from one drive account then download file from one drive account using Java SDK.

Please guide me.

Thank you.

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mehtab Siddique (MINDTREE LIMITED) 971 Reputation points
    2023-03-09T09:21:52.98+00:00

    Hi @Amol Harde,

    To download file from one drive in MS Graph using Java: Download the contents of the primary stream (file) of a driveItem. Only driveItems with the file property can be downloaded.

    GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
    
    InputStream stream = graphClient.customRequest("/me/drive/items/{item-id}/content", InputStream.class)
    	.buildRequest()
    	.get();
    

    For more information: https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=java#example

     


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


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.