Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Large File via LargeFileUploadTask not working #1806

Closed
ihudedi opened this issue Feb 13, 2024 · 42 comments · Fixed by microsoftgraph/msgraph-sdk-java-core#1548
Closed

Comments

@ihudedi
Copy link

ihudedi commented Feb 13, 2024

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();
driveItemUploadableProperties.setName("fileName");
driveItemUploadableProperties.setFileSize(fileSize);
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<DriveItemUploadableProperties> uploadTask = 
                                    new LargeFileUploadTask(graphClient.getRequestAdapter(), 
                                        uploadSession, 
                                        file, 
                                        fileSize, 
                                        DriveItemUploadableProperties::createFromDiscriminatorValue);
try{
    UploadResult<DriveItemUploadableProperties> uploadResult = uploadTask.upload();
} catch(ApiException | InterruptedException exception) {
    System.out.println(exception.getMessage());
    

}

I am failing when trying to create UploadSessin
I use in byDriveItemId also your example ("root/fileName" and it's not working
Thanks,
Itay

@araneolus
Copy link

The Mistake is at this point .byDriveItemId("root/fileName")
Try .byDriveItemId("root:/fileName:")
Then you will avoid this cliff, but you will not get any further with upload, because it always returns a ReturnCode 400 with the message "com.microsoft.kiota.ApiException: generalException". I have tried a lot, e.g. omitting the name and size in DriveItemUploadableProperties, but it didn't help. The first chunk is uploaded to the server and then the error code 400 appears.

@araneolus
Copy link

I always get the return code 400 when uploading.
I have tried it with different DriveItemUploadableProperties and maxslicesice of 327680 but unfortunately without success.
DriveItemUploadableProperties:

{
	"item": {
		"@microsoft.graph.conflictBehavior": "replace"
	}
}

or

{
	"item": {
		"@microsoft.graph.conflictBehavior": "replace"
	},
	"deferCommit": true
}

or

{
	"item":{
		"description":"test",
		"fileSize":8589114,
		"name":"test.log",
		"@microsoft.graph.conflictBehavior":"replace"
	}
}

If I use the method to upload small files, it works well

RequestInformation requestInformation = graphClient.drives().byDriveId(drive.getId()).items()
.byDriveItemId("root:/" + destination + ":").content().toPutRequestInformation(inputstream);
URI uriIncludesConflictBehavior = new URI(
requestInformation.getUri().toString() + "?@microsoft.graph.conflictBehavior=rename");
requestInformation.setUri(uriIncludesConflictBehavior);
graphClient.getRequestAdapter().sendPrimitive(requestInformation, null, InputStream.class);

@ihudedi
Copy link
Author

ihudedi commented Feb 14, 2024

Hi @araneolus
Also with byDriveItemId("root:/fileName:") not wokring
Thanks,
Itay

@araneolus
Copy link

Which error do you got ? Item already exists, or a DateTimeException ?

@ihudedi
Copy link
Author

ihudedi commented Feb 14, 2024

Hi @araneolus
Always datetime error

@araneolus
Copy link

You have to use the com.microsoft.kiota Version 1.0.2.
The cause you can find at #1785

@araneolus
Copy link

At the console I see following Debug Message, before I receive the 400 error code

14 Feb. 2024 13:38:33.573- Http2 [] DEBUG okhttp3.internal.http2.Http2Writer 258 frameHeader - >> 0x00000003 16384 DATA          
14 Feb. 2024 13:38:33.599- Http2 [] DEBUG okhttp3.internal.http2.Http2Writer 258 frameHeader - >> 0x00000003 16384 DATA          
14 Feb. 2024 13:38:33.625- Http2 [] DEBUG okhttp3.internal.http2.Http2Writer 258 frameHeader - >> 0x00000003 16384 DATA          
14 Feb. 2024 13:38:33.651- Http2 [] DEBUG okhttp3.internal.http2.Http2Writer 258 frameHeader - >> 0x00000003  3898 DATA          END_STREAM
14 Feb. 2024 13:38:33.656- Http2 [OkHttp xx-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000003     4 WINDOW_UPDATE 
14 Feb. 2024 13:38:33.656- Http2 [OkHttp xx-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000000     4 WINDOW_UPDATE 
14 Feb. 2024 13:38:33.661- Http2 [OkHttp xx-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000003  1149 HEADERS       END_HEADERS
14 Feb. 2024 13:38:33.663- Http2 [OkHttp xx-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000003   174 DATA          
14 Feb. 2024 13:38:33.663- Http2 [OkHttpxx-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000003     0 DATA          END_STREAM

@ihudedi
Copy link
Author

ihudedi commented Feb 14, 2024

Hi @araneolus
Now I am getting
Exception in thread "main" com.microsoft.graph.models.odataerrors.ODataError: Invalid request
at com.microsoft.graph.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:210)
at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:672)
at com.microsoft.kiota.ApiExceptionBuilder.(ApiExceptionBuilder.java:26)
at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:671)
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:279)
at com.microsoft.graph.drives.item.items.item.createuploadsession.CreateUploadSessionRequestBuilder.post(CreateUploadSessionRequestBuilder.java:60)
at com.microsoft.graph.drives.item.items.item.createuploadsession.CreateUploadSessionRequestBuilder.post(CreateUploadSessionRequestBuilder.java:45)
at com.bmc.cm.aft.utils.SPOUtilsTest.main(SPOUtilsTest.java:116)

@ihudedi
Copy link
Author

ihudedi commented Feb 14, 2024

Hi @araneolus
I added the updated graph core to 3.1.2 and now I am getting new error:
Exception in thread "main" com.microsoft.kiota.ApiException: generalException
at com.microsoft.kiota.ApiExceptionBuilder.withMessage(ApiExceptionBuilder.java:45)
at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse(UploadResponseHandler.java:61)
at com.microsoft.graph.core.requests.upload.UploadSliceRequestBuilder.put(UploadSliceRequestBuilder.java:69)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.uploadSlice(LargeFileUploadTask.java:207)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:131)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:111)
at com.bmc.cm.aft.utils.SPOUtilsTest.main(SPOUtilsTest.java:138)

@araneolus
Copy link

You are now as far along as I am. Welcome to the club :-)

@araneolus
Copy link

This is the structure of the 400 Response
url=https://xx-my.sharepoint.com/personal/hugo_musterman_xxx_de/_api/v2.0/drives/.../items/.../uploadSession?guid=%27...%27&overwrite=True&rename=False&dc=0&tempauth=...}

@ihudedi
Copy link
Author

ihudedi commented Feb 15, 2024

Hi @Ndiritu
same issue for version 6.2.0
Thanks,
Itay

@ramsessanchez
Copy link
Contributor

Hi @ihudedi ,
I have put together a pr to patch the largeFileUpload, hopefully we cant get this in by next minor version release, 6.3.0, apologies for the hassle and thank you for using the SDK.

@ramsessanchez
Copy link
Contributor

@petrhollayms petrhollayms changed the title Uplaod Large File via LargeFileUploadTask not wokring Upload Large File via LargeFileUploadTask not working Feb 22, 2024
@ihudedi
Copy link
Author

ihudedi commented Feb 25, 2024

Hi @ramsessanchez
Still same issue and not working in version 6.3.0
Exception in thread "main" com.microsoft.kiota.ApiException: generalException
at com.microsoft.kiota.ApiExceptionBuilder.withMessage(ApiExceptionBuilder.java:45)
at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse(UploadResponseHandler.java:62)
at com.microsoft.graph.core.requests.upload.UploadSliceRequestBuilder.put(UploadSliceRequestBuilder.java:69)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.uploadSlice(LargeFileUploadTask.java:207)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:131)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:111)
at com.bmc.cm.aft.utils.SPOUtilsTest.main(SPOUtilsTest.java:201)
Thanks,
Itay

@ihudedi
Copy link
Author

ihudedi commented Feb 28, 2024

Hi @ramsessanchez
Is there any updates?
Thanks,
Itay

@ffcdf
Copy link

ffcdf commented Feb 29, 2024

Hi @ihudedi.

With the new version of microsoft-graph 6.4.0 and microsoft-kiota 1.0.5, the first bytes of the file are loaded, but then I receive the error:

java.lang.IndexOutOfBoundsException
at java.base/java.io.FileInputStream.readBytes(Native Method)
at java.base/java.io.FileInputStream.read(FileInputStream.java:276)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.chunkInputStream(LargeFileUploadTask.java:280)

No success here yet :(...

Any successes out there?

@ihudedi
Copy link
Author

ihudedi commented Feb 29, 2024

Hi @ffcdf
It was working fine in v 5.80.
What is broken in this version?

@ramsessanchez
Copy link
Contributor

@ihudedi , we have updated the kiota-java dependencies in graph-core. Please expect to see these changes reflected on the next version of the sdk, or manually update your project to use graph-core 3.1.6. Follow up if issues persist.

@ihudedi
Copy link
Author

ihudedi commented Mar 3, 2024

Hi @ramsessanchez
I am encounter same issue as @ffcdf
Second chunk is failed in version core 3.1.6 with graph api 6.4.0
Thanks,
Itay

@abhishekmohite
Copy link

I am running into the same issue when uploading large files using code from here
https://learn.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=java & https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#large-file-upload-enhancements

I am using microsoft-graph 6.4.0 and kiota 1.0.6.

@ihudedi
Copy link
Author

ihudedi commented Mar 7, 2024

Hi @ramsessanchez
Any updates regarding this issue?
I am waiting for a fix more than 3 weeks.
It was working fine in v5.8
Thanks,
Itay

@baywet
Copy link
Member

baywet commented Mar 7, 2024

Hi everyone,
Thanks for your patience on the matter.
Ramses and I had a prolonged discussion on that topic yesterday after his analysis of the problem.
As expected, some of the confusion lies in the fact that difference services (Exchange, OneDrive for Business/SharePoint, OneDrive for consumers) behave differently.

The upload seems to be working in most cases, while some services reply with 200/201 and a response body (which is what the current implementation handles properly), others reply with 201 and no response body.
The later case derails the code here, where okhttp throws when attempting to read an inexistent body (rightfully so).
https://github.com/microsoftgraph/msgraph-sdk-java-core/blob/94093eaa875c0f4088e0be6457358b51638d379f/src/main/java/com/microsoft/graph/core/requests/upload/UploadResponseHandler.java#L54

The fix will be to check for a content-length header prior to reading the body, and return early if none is present/value is zero.

In addition to that, we'll work to triple check the implementation matches the dotnet implementation's behaviour since it's been in production for over a year now, and the adoption is much larger than java (exposing it to more potential use cases).

Thank you everyone for your patience while we take the time to get it right for good, and sorry again about the inconvenience caused.

@andreidore
Copy link

Hi

In my case, it returns 400 ( Bad request ) with this example: https://learn.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=java

It is very frustrating because the HTTP responds only with status code 400. No message, nothing. I wonder why it is a bad request.

gaurav-bagga pushed a commit to sshtools/java-nio-commons that referenced this issue Mar 8, 2024
Helper classes as follows.

1. Helper for uploading files in chunks.
2. Helper for downloading files in chunks.
3. HttpClient for some parts where ms graph falls short and in one api uploading in chunks has a known bug open @ microsoftgraph/msgraph-sdk-java#1806.
4. Object containing write info done.
@ihudedi
Copy link
Author

ihudedi commented Mar 10, 2024

Hi @baywet
Could you please let us know when fix will be release?
Thanks,
Itay

@rolansh
Copy link

rolansh commented Mar 11, 2024

@baywet
Is this relevant to a situation when in UploadResponseHandler.handlerResponse at line 60 response.isSuccessful() is false due to response.code == 404? Or does it indicate another issue?

https://github.com/microsoftgraph/msgraph-sdk-java-core/blob/94093eaa875c0f4088e0be6457358b51638d379f/src/main/java/com/microsoft/graph/core/requests/upload/UploadResponseHandler.java#L60

@ihudedi
Copy link
Author

ihudedi commented Mar 14, 2024

Hi @baywet @Ndiritu @ramsessanchez
Any updates on this issue?
I am waiting for a fix for more than a month.
This functionality was working well on v5.
Thanks,
Itay

@baywet
Copy link
Member

baywet commented Mar 18, 2024

@ihudedi I want to be clear regarding timelines and expectations here:
The help provided on GitHub comes with no SLA whatsoever, it is best effort taking other priorities and resourcing into account.
Pinging us on multiple issues just to ask for timelines doesn't help getting to a faster resolution, to the contrary, it creates more noise to sort through on our end.
If you are time constrained, the ONLY way to get support with SLAs is through opening a support ticket (Azure, Microsoft 365).
That said, we are working on a fix, you can follow the progress here microsoft/kiota-java#1119

@araneolus
Copy link

This morning I have tried the Version 1.1.1 of kiota but I got still an error by upload huge files.
I have tried both ByteArrayInputStream and Files.newInputStream as InputStream.
Maybe I was too optimistic and thought that solving the microsoft/kiota-java#1119 ticket would solve the problem.
If I can contribute anything to the solution please tell me what I should do.

21 März 2024 09:21:31.303- Http2 [OkHttp alfamediaroedermark-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000000     4 WINDOW_UPDATE 
21 März 2024 09:21:31.736- Http2 [OkHttp alfamediaroedermark-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000003  1167 HEADERS       END_HEADERS
21 März 2024 09:21:31.738- Http2 [OkHttp alfamediaroedermark-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000003   228 DATA          
21 März 2024 09:21:31.755- Http2 [OkHttp alfamediaroedermark-my.sharepoint.com] DEBUG okhttp3.internal.http2.Http2Reader 112 nextFrame - << 0x00000003     0 DATA          END_STREAM
21 März 2024 09:21:31.755- TaskRunner [] DEBUG okhttp3.internal.concurrent.TaskLoggerKt 60 log - Q10000 scheduled after   0 µs: OkHttp ConnectionPool
21 März 2024 09:21:31.755- TaskRunner [OkHttp TaskRunner] DEBUG okhttp3.internal.concurrent.TaskLoggerKt 60 log - Q10000 starting              : OkHttp ConnectionPool
21 März 2024 09:21:31.756- TaskRunner [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskLoggerKt 60 log - Q10000 run again after 299 s : OkHttp ConnectionPool
21 März 2024 09:21:31.756- TaskRunner [OkHttp TaskRunner] DEBUG okhttp3.internal.concurrent.TaskLoggerKt 60 log - Q10000 finished run in 789 µs: OkHttp ConnectionPool
21 März 2024 09:21:31.757- OneDriveObject [] DEBUG net.araneolus.vectorius.route.protocol.onedrive.OneDriveObject$1 1009 report - Uploaded 5242880 bytes of 50389889 total bytes
21 März 2024 09:21:31.759- OneDriveObject [] ERROR net.araneolus.vectorius.route.protocol.onedrive.OneDriveObject 1069 put - [put] 99facae8-bd1a-42f1-905a-c4e8d2927817 Can't write 'testfolder/8081.dmp' Range [5242880, 5242880 + 5242880) out of bounds for length 5242880
Can't write 'testfolder/8081.dmp' Range [5242880, 5242880 + 5242880) out of bounds for length 5242880
	at net.araneolus.vectorius.route.task.directories.directory.transfer.Common$4.call(Common.java:857)
	at net.araneolus.vectorius.route.task.directories.directory.transfer.Common$4.call(Common.java:1)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPerTaskExecutor$TaskRunner.run(ThreadPerTaskExecutor.java:314)
	at java.base/java.lang.VirtualThread.run(VirtualThread.java:309)

@ihudedi
Copy link
Author

ihudedi commented Mar 21, 2024

Hi @baywet
I tried latest kiota 1.1.1
and I am gettng this error:
Exception in thread "main" java.lang.IndexOutOfBoundsException
at java.base/java.io.FileInputStream.readBytes(Native Method)
at java.base/java.io.FileInputStream.read(FileInputStream.java:279)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.chunkInputStream(LargeFileUploadTask.java:280)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.uploadSlice(LargeFileUploadTask.java:204)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:131)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:111)
at com.bmc.cm.aft.utils.SPOUtilsTest.main(SPOUtilsTest.java:285)

Seems that when working with chunks the chunkInputStream in LargeFileUploadTask always set the begin instead of 0 every time to store to the buffer increase it every slice so the begin can be greater than the buffer.
begin should be zero.
private byte[] chunkInputStream(InputStream stream, int begin, int length) throws IOException {
byte[] buffer = new byte[length];
int lengthAssert = stream.read(buffer, begin, length);
assert lengthAssert == length;
return buffer;
}

If I modified the begin to be zero the upload succeeded.
But when I try to make the part 3 MB sometimes it's failed with GeneralException
Exception in thread "main" com.microsoft.kiota.ApiException: generalException
at com.microsoft.kiota.ApiExceptionBuilder.withMessage(ApiExceptionBuilder.java:45)
at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse(UploadResponseHandler.java:62)
at com.microsoft.graph.core.requests.upload.UploadSessionRequestBuilder.get(UploadSessionRequestBuilder.java:52)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.updateSessionStatus(LargeFileUploadTask.java:197)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:140)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:111)
at com.bmc.cm.aft.utils.SPOUtilsTest.main(SPOUtilsTest.java:285)

Thanks,
Itay

@baywet
Copy link
Member

baywet commented Mar 21, 2024

Thanks everyone for trying the new version and reporting the results, it helps!
We were not expecting 1.1.0 or 1.1.1 to solve this issue, right now most of the code changes to address this issue are in place with microsoft/kiota-java#1119. We're performing thorough integration tests to make sure all scenarios and different service behaviours are covered by the fix.
Thanks everyone for your patience!

@bbogaczewicz
Copy link

Hi @baywet,
I have the same issue as @ihudedi:

If I modified the begin to be zero the upload succeeded. But when I try to make the part 3 MB sometimes it's failed with GeneralException Exception in thread "main" com.microsoft.kiota.ApiException: generalException at com.microsoft.kiota.ApiExceptionBuilder.withMessage(ApiExceptionBuilder.java:45) at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse(UploadResponseHandler.java:62) at com.microsoft.graph.core.requests.upload.UploadSessionRequestBuilder.get(UploadSessionRequestBuilder.java:52) at com.microsoft.graph.core.tasks.LargeFileUploadTask.updateSessionStatus(LargeFileUploadTask.java:197) at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:140) at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:111) at com.bmc.cm.aft.utils.SPOUtilsTest.main(SPOUtilsTest.java:285)

in my case it happens for files that are fully uploaded in one slice, it looks that sometimes (not always) while trying to updateSesssionStatus, the uploadSession is not there any more. The body of the response is:

{"error":{"code":"itemNotFound","message":"The upload session was not found"}}

I'm on v.6.5.1.

@araneolus
Copy link

There is also an open ticket for this issue at
microsoftgraph/msgraph-sdk-java-core#1531

@ihudedi
Copy link
Author

ihudedi commented Apr 4, 2024

Hi @baywet @ffcdf
I saw in microsoftgraph/msgraph-sdk-java-core#1531
that you are changing the type for the upload from InputStream to FileInputStream.
I don't upload from local and I need that that stream will be inputstream because I can't upload large file not from local.
Thanks,
Itay

@ffcdf
Copy link

ffcdf commented Apr 4, 2024

Hi @ihudedi.

The first idea was actually this.

However, following @Ndiritu's suggestion, a new commit and a new pull request were made that resolved the error without significant changes. The correction basically consists of changing the line:

int lengthAssert = stream.read(buffer, begin, length);

for:

int lengthAssert = stream.read(buffer);

I believe that the next version of msgraph-sdk-java-core will already bring this correction.

@ihudedi
Copy link
Author

ihudedi commented Apr 16, 2024

Hi @petrhollayms
Any updates?

@LiuHanzhong1
Copy link

My example is from the document. Why do I sometimes succeed when uploading files:
Uploaded 13538 bytes of 13538 total bytes
Upload complete
Item ID: 015CS7XKADN44E66JPPRBZYOIE7IMTPOTK
Sometimes, although there may be error messages, OneDrive has already been uploaded:
Uploaded 13538 bytes of 13538 total bytes
Exception in thread "main" com.microsoft.kiota.ApiException: generalException
at com.microsoft.kiota.ApiExceptionBuilder.withMessage(ApiExceptionBuilder.java:45)
at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse(UploadResponseHandler.java:62)
at com.microsoft.graph.core.requests.upload.UploadSessionRequestBuilder.get(UploadSessionRequestBuilder.java:52)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.updateSessionStatus(LargeFileUploadTask.java:197)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:140)
at net.tjeerd.onedrive.OneDriveDemo.main(OneDriveDemo.java:102)

May I ask what the reason is? I spent a lot of time but there was no result

@ihudedi
Copy link
Author

ihudedi commented Apr 16, 2024

Hi @lllllllhz
I have the same issue.
Seems like there is an issue when trying to updateSessionStatus.
You can for now ignore the error if the file was uploaded completely.
I am also waiting for a fix for long time.
Thanks,
Itay

@LiuHanzhong1
Copy link

@ihudedi
Thanks for your reply

@Ndiritu
Copy link
Contributor

Ndiritu commented Apr 18, 2024

@ihudedi, another cause of the exception after the upload is specifying the wrong expected return type on successful completion of the upload task.

For OneDrive uploads, the return type should be a DriveItem object after the last chunk of the file is uploaded successfully rather than a DriveItemUploadableProperties object. The wrong return type would cause deserialization of the final payload to fail & a now completed/non-existent uploadSession gets updated throwing the exception.

I realize this may have been guided by our Upgrade Guide code sample. There's a fix to point to the docs for an accurate sample.

@ihudedi
Copy link
Author

ihudedi commented Apr 20, 2024

Hi @Ndiritu
I encountered the same issue when using DriveItem instead of DriveItemUploadableProperties
// Set body of the upload session request
DriveItemUploadableProperties driveItemUploadableProperties = new DriveItemUploadableProperties();
Map<String, Object> additionalData = new HashMap<>();
additionalData.put("@microsoft.graph.conflictBehavior", "replace");
driveItemUploadableProperties.setAdditionalData(additionalData);

    CreateUploadSessionPostRequestBody uploadSessionPostRequestBody = new CreateUploadSessionPostRequestBody();
    uploadSessionPostRequestBody.setItem(driveItemUploadableProperties);

    // Create an upload session
    UploadSession uploadSession = graphServiceClient.drives()
            .byDriveId("b!8Y-KT6ZRA0qPRfGPGztHMmxPUHODkTZHgWOrFidiD475p3XU86ktQZsM9dIWmnXx")
            .items()
            .byDriveItemId("root:/tools.jar:")
            .createUploadSession()/*.withUrl("https://graph.microsoft.com/v1.0/sites/MSFT22/ItayLibrary/bambi")*/.post(uploadSessionPostRequestBody);

    if (null == uploadSession) {
        throw new SPOException("SPOWrapper::uploadObjectInParallel: Could not create upload session");
    }

    String originalFilePath = "tools.jar";
    FileInputStream inputStream = new FileInputStream("C:\\tools.jar");
    // Create the large file upload task
    LargeFileUploadTask<DriveItem> uploadTask =
            new LargeFileUploadTask(graphServiceClient.getRequestAdapter(),
                    uploadSession,
                    inputStream,
                    18265082,
                    5 * Constants.MB,
                    DriveItem::createFromDiscriminatorValue);

    // Create a callback used by the upload provider
    IProgressCallback callback = (current, max) -> System.out.println(
            String.format("Uploaded %d bytes of %d total bytes", current, max));

    // Do the upload
    try {
        UploadResult<DriveItem> uploadResult = uploadTask.upload();
        if (uploadResult == null || !uploadResult.isUploadSuccessful()) {
            throw new SPOException(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' wasn't uploaded successfully", originalFilePath));
        } else {
            logger.debug(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' uploaded successfully", originalFilePath));
        }
    } catch (Exception e){
        e.printStackTrace();
    }

The error of general exception is always appeared when the size has chunks ( file size bigger than the chunk size)
Same issue occured when I used the DriveItemUploadableProperties class.
Seems it didn't solve the general exception

com.microsoft.kiota.ApiException: generalException
at com.microsoft.kiota.ApiExceptionBuilder.withMessage(ApiExceptionBuilder.java:45)
at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse(UploadResponseHandler.java:62)
at com.microsoft.graph.core.requests.upload.UploadSessionRequestBuilder.get(UploadSessionRequestBuilder.java:52)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.updateSessionStatus(LargeFileUploadTask.java:197)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:140)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:111)
at com.bmc.cm.aft.utils.SPOUtilsTest.main(SPOUtilsTest.java:190)

When I rerun the code for the same file exists the error doesn't exists for DriveItem and DriveItemUploadableProperties
Thanks,
Itay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.