Upload Large File Using Graph API v 6.3.0 not wotking

Itay Hudedi 0 Reputation points
2024-02-26T18:08:44.6933333+00:00

Hi,
I use your example and it's failed
/Initialize the file input stream and get the file size
InputStream file = new FileInputStream("File-Path");
long fileSize = file.available(); // Set the DriveItemUploadableProperties
// This is used to populate the request to create an upload session
DriveItemUploadableProperties driveItemUploadableProperties = new DriveItemUploadableProperties();
Map<String, Object> additionalData = new HashMap<>();
additionalData.put("@microsoft.graph.conflictBehavior", "replace");
driveItemUploadableProperties.setAdditionalData(additionalData); // Finish setting up the request body
CreateUploadSessionPostRequestBody uploadSessionPostRequestBody = new CreateUploadSessionPostRequestBody();
uploadSessionPostRequestBody.setItem(driveItemUploadableProperties); // Create the upload session
String myDriveId = graphClient.me().drive().get().getId();
UploadSession uploadSession = graphClient.drives()
.byDriveId(myDriveId)
.items()
.byDriveItemId("root:/fileName:")
.createUploadSession().post(uploadSessionPostRequestBody);
// Create the large file upload task
LargeFileUploadTask uploadTask =
new LargeFileUploadTask(graphClient.getRequestAdapter(),
uploadSession,
file,
fileSize,
DriveItemUploadableProperties::createFromDiscriminatorValue);
try{
UploadResult uploadResult = uploadTask.upload();
} catch(ApiException | InterruptedException exception) {
System.out.println(exception.getMessage()); }

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,015 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sourabh Gupta 800 Reputation points Microsoft Vendor
    2024-03-24T09:17:43.4066667+00:00

    Hi Itay Hudedi,

    Thanks for reaching out.

    This is known issue to Microsoft. You can follow the updates on the following github page.

    https://github.com/microsoftgraph/msgraph-sdk-java/issues/1806

    As an alternative. for the mean time you can use Httpclient to make http post call to the concerned end point.

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

    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.