microsoftgraph / microsoftgraph/msgraph-sdk-java

LargeFileUploadTask Upload session failed.

Open
#2,332 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:waiting-for-triage type:bug
Dominant language
Java
Stars
444
Forks
154
Avg merge
18h 28m
Merged PRs (30d)
4

Description

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_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure from the uploadFile() example, then trace the request through LargeFileUploadTask.upload and LargeFileUploadRequest.upload. Compare the upload-session request and its 401 response with the SDK version shown in the report; done means large-file uploads complete successfully rather than returning "Unauthenticated."

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.