microsoftgraph / microsoftgraph/msgraph-sdk-java
When uploading file using LargeFileUploadTask (streaming and not in one part) the file getting corrupted in the SharePoint server
還沒有人認領這個 Issue。
- 主要語言
- Java
- 星號
- 444
- 分支
- 154
- 平均合併
- 18 小時 28 分鐘
- 30 天內合併 PR
- 4
描述
Describe the bug
I am using latest version of graph api - 6.24.0
When I uploading any file using
graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId(getDriveItemIdFromRootPath(filePath)).content().put(fileContent) file is uploading correct.
When I upload via the LargeUploadTask - file is corrupted for any file such as MSOffice file or dat file or jar file.
For MSOffice the file can't be opened and for the dat file null values are being inserted to the file.
The code that I am using for the uploading in streaming is:
LargeFileUploadTask largeFileUploadTask = null;
IProgressCallback callback = null;
UploadResult uploadResult = null;
try {
int spoPartSize = 5242880;
// Set body of the upload session request
// This is used to populate the request to create an upload session
DriveItemUploadableProperties driveItemUploadableProperties = new DriveItemUploadableProperties();
driveItemUploadableProperties.getAdditionalData().put("@microsoft.graph.conflictBehavior", "replace");
// Finish setting up the request body
CreateUploadSessionPostRequestBody uploadSessionPostRequestBody = new CreateUploadSessionPostRequestBody();
uploadSessionPostRequestBody.setItem(driveItemUploadableProperties);
// Create the upload session
UploadSession uploadSession = graphServiceClient.drives()
.byDriveId(driveId)
.items()
.byDriveItemId(getDriveItemIdFromRootPath(filePath))
.createUploadSession().post(uploadSessionPostRequestBody);
if (null == uploadSession) {
throw new SPOException("SPOWrapper::uploadObjectInParallel: Could not create upload session");
}
// Create the large file upload task
largeFileUploadTask = new LargeFileUploadTask(graphServiceClient.getRequestAdapter(),
uploadSession,
fileContent,
fileSize,
spoPartSize,
DriveItem::createFromDiscriminatorValue);
if (null == largeFileUploadTask) {
throw new SPOException("SPOWrapper::uploadObjectInParallel: Could not create upload task");
}
// Create a callback used by the upload provider
callback = new SPOProgressCallback(spoFileCopy);
// Do the upload
uploadResult = largeFileUploadTask.upload(spoRequestMaxAttempts, callback);
if (uploadResult == null || !uploadResult.isUploadSuccessful()) {
throw new SPOException(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' wasn't uploaded successfully via upload method", originalFilePath));
} else {
logger.debug(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' uploaded successfully via upload method", originalFilePath));
}
} catch (Exception e) {
boolean spoIgnoreFailureWhenUploadingFileInParts = Boolean.valueOf(hostProperties.getParameterValueFromAdditionalParamsOrFromAftConfig(mftPropertiesConfig, PropertyData.spoIgnoreFailureWhenUploadingFileInParts, AdditionalParametersConsts.spoIgnoreFailureWhenUploadingFileInParts));
logger.error(String.format("Error in SPOWrapper::uploadObjectInParallel, filePath = '%s', fileSize = '%s' : %s", originalFilePath, fileSize, e.getMessage()), e);
/* try {
if (uploadTask != null && callback != null) {
uploadResult = uploadTask.resume(spoRequestMaxAttempts, callback);
if (uploadResult == null || !uploadResult.isUploadSuccessful()) {
throw new SPOException(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' wasn't uploaded successfully via resume method", originalFilePath));
} else {
logger.debug(String.format("SPOWrapper::uploadObjectInParallel: filePath= '%s' uploaded successfully via resume method", originalFilePath));
return;
}
}
} catch (Exception ex) {
logger.error(String.format("Error in SPOWrapper::uploadObjectInParallel, filePath = '%s', fileSize = '%s' : %s", originalFilePath, fileSize, e.getMessage()), e);
throw e;
} finally {
logger.debug(String.format("End SPOWrapper::uploadObjectInParallel: filePath= '%s', fileSize= %s", originalFilePath, fileSize));
}
Thanks,
Itay
Expected behavior
File should uploaded corrdct with same bytes and noit being corrupted.
How to reproduce
Uploading file using LargeFileUploadTask
SDK Version
6.24/0
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 編號。
研究方向
從與串流 fileContent 一起使用的 LargeFileUploadTask 上傳路徑開始,並將其與正常運作的 content().put(fileContent) 路徑進行比較。使用大於一個 part 的二進位檔案進行重現,然後檢查 multipart 請求資料和上傳工作階段處理。對於 Office、DAT 和 JAR 檔案,上傳的檔案與來源檔案具有相同的位元組即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- api
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100