我正在使用 PHP 将文件复制到 Azure 服务上。是否可以生成一个链接,允许用户使用 Office 365 在线自动打开此存储的文档?当前,返回 URL 将存储的文档下载到用户本地存储。这是我的 PHP 代码,它使用 Microsoft Azure PHP SDK。
require_once 'vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\ServiceException;
// Create blob REST proxy.
$connectionString="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$content = fopen("demo.doc", "r");
$blob_name = "demo.doc";
try {
//Upload blob
$blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content);
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/library/azure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
最佳答案
默认情况下,Office 365 无法打开存储在其他位置(不在 Office 365 中)的文件。但是,您可以尝试使用WOPI与 Office Online 集成的协议(protocol)。 WOPI 协议(protocol)使 Office Online 能够访问和更改存储在您的服务中的文件。
另一个解决方法是您可以考虑将文件上传到 Office 365。您可以引用下面的 REST 在线创建/上传项目到 SharePoint:
POST: https://graph.microsoft.com/v1.0/me/drive/root/children
authorization: bearer {token}
content-type: application/json
{
"name":"filename.docx",
"file":{}
}
PUT: https://graph.microsoft.com/v1.0/me/drive/root:/RESTFei.docx:/content
authorization: bearer {token}
Content-Type: application/msword
<@INCLUDE *C:\Users\username \Desktop\test.docx*@>
有关使用 Microsoft Graph 进行开发的更多详细信息,请参阅here .
关于php - 是否可以使用 Office 365 在线打开存储在 Azure 上的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37684233/