php - 是否可以使用 Office 365 在线打开存储在 Azure 上的文档?

标签 php azure azure-storage azure-blob-storage office365api

我正在使用 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/

相关文章:

asp.net - 创建Azure存储帐户卡在Azure网站上

c# - Azure 表服务 2012 年 10 月版本中的投影,不使用字符串来引用列

php - Magento 可配置产品在多商店网站的前端缺货

node.js - 保持azure VM上的nodejs服务器运行

java - 使用 Java 的 Azure 表存储时间戳不得为 null

azure - 如何从 Windows Azure 中发出 Web 请求

azure - 我应该在 test_configurations.json 中填充哪些字段?

php - 显示结果不重复

php - MySQL 将 IP 存储为 int 以获得更高的性能?

php - 从 IS NOT NULL 的数据中查询列