问题描述
我正在尝试使用Microsoft Graph Java SDK 2.10将大型(> 4mb)附件上载到Office 365中的现有邮件。我正在遵循以下指示:https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=java
我已经成功创建了上传会话,并获得了一个类似于文档中示例的uploadUrl值。然后,我使用ChunkedUploadProvider将PUT启动到该网址。
// Create an upload session
UploadSession uploadSession = client.me()
.messages(messageId).attachments()
.createUploadSession(attachmentItem)
.buildrequest()
.post();
ChunkedUploadProvider<AttachmentItem> chunkedUploadProvider =
new ChunkedUploadProvider<AttachmentItem>
(uploadSession,client,fileStream,attachmentItem.size,AttachmentItem.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 = { 12 * 320 * 1024 }; // still < 4MB as API recommended
// Do the upload
try {
chunkedUploadProvider.upload(callback,customConfig);
} catch (Exception e) {
log.error("Upload attachment file name {} for message id {}",fileAttachment.name,messageId,e);
}
我的问题是我得到http 401(未授权)作为响应:
{
"error": {
"code": "InvalidMsaTicket","message": "ErrorCode: \u0027PP_E_RPS_CERT_NOT_FOUND\u0027. Message: \u0027 Internal error: spRPSTicket-\u003eProcesstoken Failed. Failed to call CRPSDataCryptImpl::UnpackData: Internal error: Failed to decrypt data. :Failed to get session key. RecipientId\u003d293577. spCache-\u003eGetCacheItem returns error.:Cert Name: (null). SKI: 3bd72187c709b1c40b994f8b496a5b9ebd2f9b0c...\u0027","innerError": {
"requestId": "7276a164-9c13-41cc-b46a-4a86303017a6","date": "2020-09-17T04:55:15"
}
}
}
我注意到创建上传会话的请求是:
https://graph.microsoft.com/v1.0/me/messages/AqmkADAwATM3ZmYAZS0xNWU2LTc4N1agAAAA==/attachments
uploadUrl为:
https://outlook.office.com/api/v2.0/Users('00037ffe-15e6-787e-0000-00000')/Messages('AqmkADAwATM3ZmYAZS0xNVtUUgAAAA==')/AttachmentSessions('AqmkADAwwAAAA=')?authtoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IktmYUNIUlN6bllHMmNIdDRobk9JQnpndlU5MD0iL
这是一个不同的API(图形与Outlook)。
任何帮助将不胜感激。谢谢。
解决方法
我的坏。该请求不应包含授权标头:
不指定授权请求标头。 PUT查询使用来自uploadUrl属性的预先认证的URL,该URL允许访问https://outlook.office.com域。
删除了Authorization标头,请求正常运行。