0

我正在尝试使用以下代码,但收到“消息:受众声明值对当前资源无效。受众声明为‘ https://graph.microsoft.com ’,请求 URL 为‘ https://outlook。 office.com/api/beta/Users ..."

我在 provider.GetUploadChunkRequests(); 拨打以下电话:

AttachmentItem attachmentItem= new AttachmentItem
            { 
                Name = [Name],
                AttachmentType = AttachmentType.File,
Size = [Size]
            };

var session = graphClient.Users[USEREMAIL].Messages[MESSAGEID].Attachments.CreateUploadSession(attachmentItem).Request().PostAsync().Result;
            var stream = new MemoryStream(BYTEARRAY);
            var maxSizeChunk = DEFAULT_CHUNK_SIZE;
            var provider = new ChunkedUploadProvider(session, graphClient, stream, maxSizeChunk);
            var chunkRequests = provider.GetUploadChunkRequests();

(我正在使用graphClient成功发送电子邮件,并且还使用它使用uploadSession方法上传大文件)

4

1 回答 1

0

来自GitHub 上Andrue Eastman

您很可能会因为使用 ChunkedUploadPorvider 而不是使用 FileUploadTask 上传设置 Auth 标头的附件而收到错误,从而导致您收到错误。

要使用文件上传任务,请按照以下步骤操作

首先创建一个上传会话并将其交给任务,如图所示。

// Create task
var maxSliceSize = 320 * 1024; // 320 KB - Change this to your chunk size. 4MB is the default.
LargeFileUploadTask<FileAttachment> largeFileUploadTask = new LargeFileUploadTask<FileAttachment>(uploadSession, stream, maxSliceSize);

创建上传监视器(可选)

// Setup the progress monitoring
IProgress<long> progress = new Progress<long>(progress =>
{
    Console.WriteLine($"Uploaded {progress} bytes of {stream.Length} bytes");
});

该服务仅返回可以从结果对象中读取的位置 URI,如下所示。

UploadResult<FileAttachment> uploadResult = null;
try
{
    uploadResult = await largeFileUploadTask.UploadAsync(progress);
    if (uploadResult.UploadSucceeded)
    {
        Console.WriteLine(uploadResult.Location);//the location of the object
    }
}
catch (ServiceException e)
{
    Console.WriteLine(e.Message);
}
于 2020-01-31T14:48:34.553 回答