我正在尝试在 MS-PowerPoint 中打开演示文稿。我已经为它创建了一个加载项。它有一个按钮,单击 s3 中的按钮即可检索文件,然后将文件上传到登录用户的 OneDrive 中。 我可以在后端使用 Microsoft Graph API 和 S3 API 来实现它。 但是,我无法替换当前在 PowerPoint 中打开的文件,图形 API 给出 423 错误,因为我无法修改已打开的文件。 还有其他方法可以实现这一目标吗? 我可以使用 Office JavaScript API 吗?如果是,我如何解析从 S3 获得的 blob 文件的内容? 会有多复杂?
async function uploadToOneDrive(fileBlob, fileName, accessToken) {
const uploadUrl = `https://graph.microsoft.com/v1.0/me/drive/root:/Documents/${fileName}:/content`;
try {
const response = await fetch(uploadUrl, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/octet-stream'
},
body: fileBlob
});
if (!response.ok) {
throw new Error(`Error uploading file to OneDrive: ${response.statusText}`);
}
} catch (error) {
console.error('Upload to OneDrive failed:', error);
}
}
我正在使用 Graph API 上传文件并使用 MSAL 库,因为我之前使用过它,但是这会失败,并且会为我打开的文件提供 423 错误。
如果你
} catch (error) {
console.error('Upload to OneDrive failed:', error);
未激活,请使用 PowerShell 脚本检查您的代码。
Start-Process -FilePath "C:\Path\To\YourExecutable.exe" -ArgumentList "arg1", "arg2"
-- With parameters using JS
-- Using norm Powershell opening
.\YourExecutable.exe
-- Paths
C:/Path/Path/Path/File
我不擅长编码,我无法回答一些编码,但我很乐意帮助其中一些,如果我错了,我很抱歉!