gpt4 book ai didi

onedrive - Microsoft Graph SDK OneDrive uploadSession 错误代码 :BadRequest

转载 作者:行者123 更新时间:2023-12-04 08:46:02 25 4
gpt4 key购买 nike

我正在尝试使用 java sdk 将文件上传到 OneDrive 特殊文件夹,但出现以下错误
错误代码:BadRequest 错误消息:使用“microsoft.graph.createUploadSession”的相同绑定(bind)参数发现了多个操作重载。
这是我正在使用的 java 代码片段

private void uploadFile(IGraphServiceClient graphClient, File localFile, String onedriveFileName) throws IOException, InterruptedException {
// Get an input stream for the file
InputStream fileStream = new FileInputStream(localFile);
long streamSize = localFile.length();

// Create a callback used by the upload provider
IProgressCallback<DriveItem> callback = new IProgressCallback<DriveItem>() {
@Override
// Called after each slice of the file is uploaded
public void progress(final long current, final long max) {
LOGGER.trace(String.format("Uploaded %d bytes of %d total bytes", current, max));
}

@Override
public void success(final DriveItem result) {
LOGGER.info(String.format("Uploaded file with ID: %s", result.id));
}

public void failure(final ClientException ex) {
LOGGER.error(String.format("Error uploading file: %s", ex.getMessage()));
}
};

try {
// Create an upload session
UploadSession uploadSession = graphClient
.me()
.drive().special("approot")
.itemWithPath(onedriveFileName)
.createUploadSession(new DriveItemUploadableProperties())
.buildRequest()
.post();

ChunkedUploadProvider<DriveItem> chunkedUploadProvider =
new ChunkedUploadProvider<DriveItem>
(uploadSession, graphClient, fileStream, streamSize, DriveItem.class);

// Config parameter is an array of integers
// customConfig[0] indicates the max slice size
// Max slice size must be a multiple of 320 KiB
int[] customConfig = {320 * 1024};

// Do the upload
chunkedUploadProvider.upload(callback, customConfig);

} catch(IOException ex){
throw ex;
} catch (Exception ex) {
throw ex;
}
}
任何帮助表示赞赏。
谢谢

最佳答案

我的问题是我在文件名中有特殊字符,删除它们为我修复了它。

关于onedrive - Microsoft Graph SDK OneDrive uploadSession 错误代码 :BadRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64316220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com