Outlook 插件上传 FileReference 作为附件
Outlook Plugin upload FileReference as attachment
我正在开发一个 outlook 插件,当用户撰写消息时需要上传参考文件而不是文件附件。
我尝试过使用这 3 种方法:
- addFileAttachmentAsync(uri, attachmentName, [选项],
[回调])
- addItemAttachmentAsync(itemId, attachmentName,
[选项]、[回调])
- makeEwsRequestAsync(数据,回调,[userContext])
三种方法的结果:
- 无法添加参考文件
- MessageText":"您无法附加自己。","ResponseCode":"ErrorCannotAttachSelf","ResponseClass":"Error"}]}}}
- HTTP 500 错误。
第二种方法代码:
var messageId = await getMessageItemId();
var exchangeAttachment = await uploadAttachmentToExchange(accessToken, messageId, attachment.name,fileUploaded.webUrl);
await addReferenceAttachment(exchangeAttachment.id, attachment.name);
var uploadAttachmentToExchange = async function(accessToken, messageId, fileName, fileUrl){
var OneDriveURL = "https://graph.microsoft.com/beta/me/messages/"+messageId+"/attachments";
var payload = JSON.stringify({
"@odata.type": "#microsoft.graph.referenceAttachment",
"name": fileName,
"sourceUrl": fileUrl,
"providerType": "oneDriveBusiness",
"permission": "organizationEdit",
"isFolder" : false,
"isInline" : false
}) ;
return new Promise((successCallback, failureCallback) => {
$.ajax({
method: "POST",
contentType: 'application/json',
dataType: 'json',
headers: {
'Authorization': 'Bearer '+ accessToken
},
url: OneDriveURL,
data : payload
})
.done(function( response ) {
successCallback(response);
})
.fail(function(resultat, status, error) {
failureCallback(resultat);
});
});
};
var getMessageItemId = async function(){
return new Promise((successCallback, failureCallback) => {
mailboxItem.getItemIdAsync(function(asyncResult){
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
failureCallback(asyncResult.error.message);
} else {
successCallback(asyncResult.value);
}
});
});
};
var addReferenceAttachment = async function(itemId, attachmentName){
return new Promise((successCallback, failureCallback) => {
mailboxItem.addItemAttachmentAsync(itemId, attachmentName, {}, function(asyncResult){
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
failureCallback(asyncResult.error.message);
} else {
successCallback(asyncResult);
}
});
});
};
第三种方法代码:
var messageId = await getMessageItemId();
await uploadAttachmentUsingEWSAPI(messageId);
var uploadAttachmentUsingEWSAPI = async function (messageId){
var request =
'<?xml version="1.0" encoding="utf-8"?>'+
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
' xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"'+
' xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"'+
' xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">'
' <soap:Header>'
' <t:RequestServerVersion Version="Exchange2007_SP1" />'
' <t:TimeZoneContext>'
' <t:TimeZoneDefinition Id="Central Standard Time" />'
' </t:TimeZoneContext>'
' </soap:Header>'
' <soap:Body>'
' <m:CreateAttachment>'
' <m:ParentItemId Id="'+ messageId +'" />'
' <m:Attachments>'
' <t:FileAttachment>'
' <t:Name>FileAttachment.txt</t:Name>'
' <t:Content>VGhpcyBpcyBhIGZpbGUgYXR0YWNobWVudC4=</t:Content>'
' </t:FileAttachment>'
' </m:Attachments>'
' </m:CreateAttachment>'
' </soap:Body>'
'</soap:Envelope>';
console.log(request);
return sendEWSRequest(request);
};
var sendEWSRequest = async function(request){
return new Promise((successCallback, failureCallback) => {
Office.context.mailbox.makeEwsRequestAsync(request, function(asyncResult){
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
failureCallback(asyncResult.error.message);
} else {
successCallback(asyncResult);
}
});
});
};
三种方法中的 None 有效。
有没有办法上传像这样的云附件? :
如果是,使用的方法是什么?
此致
当前的功能:您请求的使用插件 API 添加云附件作为参考,不是该产品的一部分。我们在 Tech Community Page 上跟踪 Outlook 加载项功能请求。请在那里提交您的请求并选择合适的标签。在我们进行规划过程时,会考虑技术社区的功能请求。
我正在开发一个 outlook 插件,当用户撰写消息时需要上传参考文件而不是文件附件。
我尝试过使用这 3 种方法:
- addFileAttachmentAsync(uri, attachmentName, [选项], [回调])
- addItemAttachmentAsync(itemId, attachmentName, [选项]、[回调])
- makeEwsRequestAsync(数据,回调,[userContext])
三种方法的结果:
- 无法添加参考文件
- MessageText":"您无法附加自己。","ResponseCode":"ErrorCannotAttachSelf","ResponseClass":"Error"}]}}}
- HTTP 500 错误。
第二种方法代码:
var messageId = await getMessageItemId();
var exchangeAttachment = await uploadAttachmentToExchange(accessToken, messageId, attachment.name,fileUploaded.webUrl);
await addReferenceAttachment(exchangeAttachment.id, attachment.name);
var uploadAttachmentToExchange = async function(accessToken, messageId, fileName, fileUrl){
var OneDriveURL = "https://graph.microsoft.com/beta/me/messages/"+messageId+"/attachments";
var payload = JSON.stringify({
"@odata.type": "#microsoft.graph.referenceAttachment",
"name": fileName,
"sourceUrl": fileUrl,
"providerType": "oneDriveBusiness",
"permission": "organizationEdit",
"isFolder" : false,
"isInline" : false
}) ;
return new Promise((successCallback, failureCallback) => {
$.ajax({
method: "POST",
contentType: 'application/json',
dataType: 'json',
headers: {
'Authorization': 'Bearer '+ accessToken
},
url: OneDriveURL,
data : payload
})
.done(function( response ) {
successCallback(response);
})
.fail(function(resultat, status, error) {
failureCallback(resultat);
});
});
};
var getMessageItemId = async function(){
return new Promise((successCallback, failureCallback) => {
mailboxItem.getItemIdAsync(function(asyncResult){
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
failureCallback(asyncResult.error.message);
} else {
successCallback(asyncResult.value);
}
});
});
};
var addReferenceAttachment = async function(itemId, attachmentName){
return new Promise((successCallback, failureCallback) => {
mailboxItem.addItemAttachmentAsync(itemId, attachmentName, {}, function(asyncResult){
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
failureCallback(asyncResult.error.message);
} else {
successCallback(asyncResult);
}
});
});
};
第三种方法代码:
var messageId = await getMessageItemId();
await uploadAttachmentUsingEWSAPI(messageId);
var uploadAttachmentUsingEWSAPI = async function (messageId){
var request =
'<?xml version="1.0" encoding="utf-8"?>'+
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
' xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"'+
' xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"'+
' xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">'
' <soap:Header>'
' <t:RequestServerVersion Version="Exchange2007_SP1" />'
' <t:TimeZoneContext>'
' <t:TimeZoneDefinition Id="Central Standard Time" />'
' </t:TimeZoneContext>'
' </soap:Header>'
' <soap:Body>'
' <m:CreateAttachment>'
' <m:ParentItemId Id="'+ messageId +'" />'
' <m:Attachments>'
' <t:FileAttachment>'
' <t:Name>FileAttachment.txt</t:Name>'
' <t:Content>VGhpcyBpcyBhIGZpbGUgYXR0YWNobWVudC4=</t:Content>'
' </t:FileAttachment>'
' </m:Attachments>'
' </m:CreateAttachment>'
' </soap:Body>'
'</soap:Envelope>';
console.log(request);
return sendEWSRequest(request);
};
var sendEWSRequest = async function(request){
return new Promise((successCallback, failureCallback) => {
Office.context.mailbox.makeEwsRequestAsync(request, function(asyncResult){
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
failureCallback(asyncResult.error.message);
} else {
successCallback(asyncResult);
}
});
});
};
三种方法中的 None 有效。 有没有办法上传像这样的云附件? :
如果是,使用的方法是什么?
此致
当前的功能:您请求的使用插件 API 添加云附件作为参考,不是该产品的一部分。我们在 Tech Community Page 上跟踪 Outlook 加载项功能请求。请在那里提交您的请求并选择合适的标签。在我们进行规划过程时,会考虑技术社区的功能请求。