根据Microsoft Graph文档中的Attach large files to Outlook messages as attachments,我正在尝试在C#中执行步骤1。
我使用的GraphServiceClient
和消息id
在上传小型附件时效果很好。但是,在上传大型附件时,出现此错误:
不支持OData请求。
根据下面的代码,我相信我已经正确遵循了文档。
有人知道为什么我会收到我的错误消息吗?
var attachmentItem = new AttachmentItem
{
AttachmentType = AttachmentType.File,
Name = file.Name,
Size = file.Length //3.5MB test file
};
UploadSession session = await GraphAPIConnection.GraphClient
.Me
.Messages[message.Id]
.Attachments
.CreateUploadSession(attachmentItem)
.Request()
.PostAsync();
我已验证file
,message
和attachmentItem
属性在尝试调用之前均已正确创建。
使用软件包:
更新1:
我发现创建GraphServiceClient时的端点使用的是v1.0,而不是beta。更改后,我的代码中进一步遇到以下错误:
InvalidAudience
using (Stream fileStream = System.IO.File.OpenRead(file.FullName))
{
if (session != null)
{
int maxSizeChunk = (320 * 1024) * 4;
List<Exception> exceptions = new List<Exception>();
byte[] readBuffer = new byte[maxSizeChunk];
ChunkedUploadProvider uploadProvider =
new ChunkedUploadProvider
(session, GraphAPIConnection.GraphClient, fileStream, maxSizeChunk);
IEnumerable<UploadChunkRequest> chunkRequests =
uploadProvider
.GetUploadChunkRequests();
foreach (UploadChunkRequest request in chunkRequests)
{
UploadChunkResult result =
await uploadProvider
.GetChunkRequestResponseAsync
(request, readBuffer, exceptions);
//ERROR HERE
}
}
}
我的印象是Graph不需要使用替代的Outlook API。但是,无论如何,上传会话似乎都在使用它:
request.RequestUrl: https://outlook.office.com:443/api/beta/ ...
request.Client.BaseUrl: https://graph.microsoft.com/beta
这是否意味着我需要其他范围才能正确访问该API?
我是否需要生成一个新的客户端?