microsoftgraph / microsoftgraph/msgraph-sdk-java
LargeFileUploadTask Upload session failed.
還沒有人認領這個 Issue。
- 主要語言
- Java
- 星號
- 444
- 分支
- 154
- 平均合併
- 18 小時 28 分鐘
- 30 天內合併 PR
- 4
描述
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_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
重現 uploadFile() 範例中的失敗,然後追蹤請求經過 LargeFileUploadTask.upload 和 LargeFileUploadRequest.upload 的過程。將上傳工作階段請求及其 401 回應與報告中顯示的 SDK 版本進行比較;當大型檔案上傳成功完成,而不是回傳 "Unauthenticated" 時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- api
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 28/100