msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

LargeFileUploadTask Upload session failed.

Open cl-geniatech opened this issue 9 months ago • 2 comments

Describe the bug

For large file uploads using com.microsoft.graph:microsoft-graph:5.80.0, it always prompts: com.microsoft.graph.core.ClientException: Upload session failed. Below is the full log

`DriveUpload DriveUpload com.microsoft.graph.core.ClientException: Error while executing the request at com.microsoft.graph.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:260) at com.geniatech.onedrive.DriveUpload.uploadFile(DriveUpload.java:119) at com.geniatech.onedrive.DriveUpload.run(DriveUpload.java:45) Caused by: java.util.concurrent.ExecutionException: com.microsoft.graph.core.ClientException: Upload session failed. at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:359) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1921) at com.microsoft.graph.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:255) at com.geniatech.onedrive.DriveUpload.uploadFile(DriveUpload.java:119)  at com.geniatech.onedrive.DriveUpload.run(DriveUpload.java:45)  Caused by: com.microsoft.graph.core.ClientException: Upload session failed. at com.microsoft.graph.tasks.LargeFileUploadRequest.upload(LargeFileUploadRequest.java:107) at com.microsoft.graph.tasks.LargeFileUploadTask.uploadAsync(LargeFileUploadTask.java:167) at com.microsoft.graph.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:255)  at com.geniatech.onedrive.DriveUpload.uploadFile(DriveUpload.java:119)  at com.geniatech.onedrive.DriveUpload.run(DriveUpload.java:45)  Caused by: com.microsoft.graph.core.ClientException: Error code: unauthenticated Error message: Unauthenticated

                                                                                                PUT https://my.microsoftpersonalcontent.com/personal/2fdc61d53bdc14dc/_api/v2.0/drive/items/016254SOI4F63FDODDGFD2HROPQGFCQN4Y/uploadSession?guid=%271be67694-c6e8-490b-bb91-5928bb3e34a8%27&overwrite=True&rename=False&dc=0&tempauth=v1e.eyJzaXRlaWQiOiIxMGEzZDNiMy0wZjYxLTRjZGItOWU3OC02OTcxMTlhMjIwMzQiLCJhcHBfZGlzcGxheW5hbWUiOiJHcmFwaCIsImFwcGlkIjoiMTA3YjJiMzEtMTgyYi00NWQzLTg0MjMtODJiNDRmYThkOTdmIiwiYXVkIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwL215Lm1pY3Jvc29mdHBlcnNvbmFsY29udGVudC5jb21AOTE4ODA0MGQtNmM2Ny00YzViLWIxMTItMzZhMzA0YjY2ZGFkIiwiZXhwIjoiMTc0MTkyNDkxMSJ9.MnNt1k9jB4BFWdYtXXI_XiAHUKX9RR5uC3afHu0CMEvvtEMOiRWVbO6lQqm_efwW2tGgZmwY4Pgjxr1OErnINH6iyZiZDitnYuJOXUncig4N43UCoTUnv76Qaq9LdccPaa4fR-4svB3ljphSJjfO-r7aBLogUfRm2qDFNhcChSbMVg1ljwMrrKCAUz50Dk8MKMCijkr5Af_9incN6Gevsg6Jg2yO_thDpE0P3rYCQd0Pom5AGbmXUel2y0dEoBNJlckCjGD7x0RZe6bVLU2-S7cJGIJmuqlL2WvopHaXGMkIx4fi8f9HW2UbBRb1OL_qcjywIrzOJxFtdiRWusWwGr_FKMkNYPCZeWLqZZDPbAcW_7C4kmDu61PQzIsDENzA0m9DXnS6zSCuBdV7wd_r8ZQfNlhPp6has8IcNH1_XC3sMKrmIlOWFsy8g4jrYm1h7xnS6-87FoMiYMhc3VwQQA.PLtp6iHBMdJ7GperLV5mVeBcj_X_x4bl7eYCXFu4R9U
                                                                                                SdkVersion : graph-java/v5.80.0
                                                                                                Content-Range : bytes 0-1652626/1652627
                                                                                                
                                                                                                
                                                                                                401 : 
                                                                                                [...]
                                                                                                
                                                                                                [Some information was truncated for brevity, enable debug logging for more details]
                                                                                                	at com.microsoft.graph.tasks.LargeFileUploadResponse.<init>(LargeFileUploadResponse.java:95)
                                                                                                	at com.microsoft.graph.tasks.LargeFileUploadResponseHandler.generateResult(LargeFileUploadResponseHandler.java:95)
                                                                                                	at com.microsoft.graph.tasks.LargeFileUploadResponseHandler.generateResult(LargeFileUploadResponseHandler.java:55)
                                                                                                	at com.microsoft.graph.http.CoreHttpProvider.processResponse(CoreHttpProvider.java:435)
                                                                                                	at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:408)
                                                                                                	at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:225)
                                                                                                	at com.microsoft.graph.tasks.LargeFileUploadRequest.upload(LargeFileUploadRequest.java:98)
                                                                                                	... 4 more
                                                                                                Caused by: com.microsoft.graph.http.GraphServiceException: Error code: unauthenticated
                                                                                                Error message: Unauthenticated

2025-03-13 12:02:02.899 26905-27095 Netdisk com.geniatech.knote.netdisc E PUT https://my.microsoftpersonalcontent.com/personal/2fdc61d53bdc14dc/_api/v2.0/drive/items/016254SOI4F63FDODDGFD2HROPQGFCQN4Y/uploadSession?guid=%271be67694-c6e8-490b-bb91-5928bb3e34a8%27&overwrite=True&rename=False&dc=0&tempauth=v1e.eyJzaXRlaWQiOiIxMGEzZDNiMy0wZjYxLTRjZGItOWU3OC02OTcxMTlhMjIwMzQiLCJhcHBfZGlzcGxheW5hbWUiOiJHcmFwaCIsImFwcGlkIjoiMTA3YjJiMzEtMTgyYi00NWQzLTg0MjMtODJiNDRmYThkOTdmIiwiYXVkIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwL215Lm1pY3Jvc29mdHBlcnNvbmFsY29udGVudC5jb21AOTE4ODA0MGQtNmM2Ny00YzViLWIxMTItMzZhMzA0YjY2ZGFkIiwiZXhwIjoiMTc0MTkyNDkxMSJ9.MnNt1k9jB4BFWdYtXXI_XiAHUKX9RR5uC3afHu0CMEvvtEMOiRWVbO6lQqm_efwW2tGgZmwY4Pgjxr1OErnINH6iyZiZDitnYuJOXUncig4N43UCoTUnv76Qaq9LdccPaa4fR-4svB3ljphSJjfO-r7aBLogUfRm2qDFNhcChSbMVg1ljwMrrKCAUz50Dk8MKMCijkr5Af_9incN6Gevsg6Jg2yO_thDpE0P3rYCQd0Pom5AGbmXUel2y0dEoBNJlckCjGD7x0RZe6bVLU2-S7cJGIJmuqlL2WvopHaXGMkIx4fi8f9HW2UbBRb1OL_qcjywIrzOJxFtdiRWusWwGr_FKMkNYPCZeWLqZZDPbAcW_7C4kmDu61PQzIsDENzA0m9DXnS6zSCuBdV7wd_r8ZQfNlhPp6has8IcNH1_XC3sMKrmIlOWFsy8g4jrYm1h7xnS6-87FoMiYMhc3VwQQA.PLtp6iHBMdJ7GperLV5mVeBcj_X_x4bl7eYCXFu4R9U SdkVersion : graph-java/v5.80.0 Content-Range : bytes 0-1652626/1652627

                                                                                                401 : 
                                                                                                [...]
                                                                                                
                                                                                                [Some information was truncated for brevity, enable debug logging for more details]
                                                                                                	... 10 more`

Expected behavior

Creating files and downloading files are normal, uploading files is not clear why it is abnormal, it was still normal last year

How to reproduce

`private void uploadFile() throws Exception { // Get an input stream for the file File file = new File(filepath); String itemPath = "/" + type.getFolderName() + "/" + file.getName(); LogUtils.i(TAG, "itemPath=" + itemPath + ";type=" + type); InputStream fileStream = Files.newInputStream(file.toPath()); long streamSize = file.length();

    // Create a callback used by the upload provider
    // Called after each slice of the file is uploaded
    IProgressCallback callback = (current, max) -> {
        int progress = (int) (current * 100 / max);
        listener.onMessage(true, progress);
        LogUtils.i(TAG, "current=" + current + ";max=" + max + ";progress=" + progress);

        try {
            if (isInterrupted()) {
                LogUtils.i(TAG, "fileStream.close=");
                fileStream.close();
            }
        } catch (IOException e) {
            LogUtils.e(TAG, "uploadFile", e);
        }
    };

    DriveItemCreateUploadSessionParameterSet uploadParams = DriveItemCreateUploadSessionParameterSet.newBuilder()
            .withItem(new DriveItemUploadableProperties()).build();

    // Create an upload session
    UploadSession uploadSession = getGraphServiceClient(token)
            .me()
            .drive()
            .root()
            // itemPath like "/Folder/file.txt"
            // does not need to be a path to an existing item
            .itemWithPath(itemPath)
            .createUploadSession(uploadParams)
            .buildRequest()
            .post();

    LargeFileUploadTask<DriveItem> largeFileUploadTask = new LargeFileUploadTask<>(uploadSession, getGraphServiceClient(token), fileStream, streamSize, DriveItem.class);
    // Do the upload
    largeFileUploadTask.upload(0, null, callback);
}`

SDK Version

No response

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

cl-geniatech avatar Mar 13 '25 04:03 cl-geniatech

I have the same problem both on the PC with hand-written REST queries and on Android with the graph SDK.

I found out that the reason is that the uploads (PUT) of the file ranges may not contain any authorization headers, even though this worked in the past. This is documented here: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online (last item in the Remarks section).

By removing the authorization header, I could fix this in my handwritten PC code.

On Android, I'm using this graph SDK, which apparently also includes the authorization. I just upgraded to v5.80.0 in the hope that this would resolve the issue, but it does not.

I did not manage to upgrade to graph SDK v6.x because of the unclear / non-existing documentation on how to implement AuthenticationProvider when instantiating GraphServiceClient.

Is there any information whether this issue is resolved in v6.x or will there be a patch release for v5.x ?

This issue is a major problem for all of my users and my only advice to them at the moment is to switch away from using OneDrive and using one of the alternative providers.

farindk avatar Apr 11 '25 12:04 farindk

I am seeing this error too. I am in the process of attempting to upgrade to 6.x, but with a basic test in 6.x I get an ApiException with a very similar error:

The OneDrive account configured does not have sufficient permissions to upload files.

It looks to me like a change to the API was made that has put it out of sync with the Java clients.

In any case, ideally we could get a fix to keep 5.x working.

worpet avatar May 12 '25 22:05 worpet