onlyoffice 使用记录(前端开发角度)

前端和Web文档生成器服务器交互

对于与 Web 文档生成器服务的交互,使用 POST 请求。 请求参数在请求正文中以 JSON 格式输入。 请求被发送到 https://documentserver/docbuilder 地址,其中 documentserver 是安装了 ONLYOFFICE 文档服务器的服务器的名称,例如服务部署在http://10.1.32.41:4200,那请求的地址就是http://10.1.32.41:4200/docbuilder。本地可以使用postman来模拟请求,请求的body为:

javascript 复制代码
{
    "async": false,
    "url": "https://test.com/pan/downloads/6c9c5394d2cde725fdd0b3684ab5d4da.docbuilder"
}

其中url表示docbuilder脚本的绝对地址。

发送post请求后,正常会返回

javascript 复制代码
{
    "key": "bld_efebb2986f314678",
    "urls": {
        "Api.pptx": "http://10.1.54.16:8000/cache/files/data/bld_efebb2986f314678/output/Api.pptx/Api.pptx?md5=Jct57-pmrac2U1PRvz-XjQ&expires=1726037649&shardkey=10.1.58.34new.pptx11725938741963&filename=Api.pptx"
    },
   "end": true

其中key就是我们要在config.document.key中配置的key值,注意,要把key的前缀bld_去掉,只保留efebb2986f314678,否则报错:An error has occurred while opening the file.

config如下:

typescript 复制代码
    config: IConfig = {
        document: {
            fileType: "pptx",
            key: "efebb2986f314678", //key值需要把前缀bld_去掉
            title: "test.pptx",
            url: "http://10.1.54.16:8000/cache/files/data/bld_efebb2986f314678/output/Api.pptx/Api.pptx?md5=Jct57-pmrac2U1PRvz-XjQ&expires=1726037649&shardkey=10.1.58.34new.pptx11725938741963&filename=Api.pptx"
        },
        height: "600px",
        documentType: "slide",
        editorConfig: {
            callbackUrl: "http://10.1.54.16:8000/dummyCallback"
        },
    }
相关推荐
Lank_M2 小时前
白底都占八成,PNG 为何只在图表页赢过 JPG
前端
张一凡932 小时前
给 Coding Agent 加一道"架构闸门":Jin 是如何做到"先审架构、再写代码、不漂移"的
前端·后端·agent
Linye2 小时前
AI 写的 HTML 原型全是空壳?聊聊真实 DOM 交互避坑
前端·人工智能
ZANE2 小时前
纯前端实现的 PDF 与图片互相转换工具技术实现
前端
Swot3 小时前
SvelteKit Remote Functions 使用指南
前端·后端
Cooper253 小时前
三源热榜去重加 AI 摘要:URL 唯一键踩出的三个坑
前端·python
Yk酱228403 小时前
A2UI探索随笔-技术选型
前端
前端繁华如梦3 小时前
# 从 73000 行压缩代码到 TypeScript 模块化:我把一个 Three.js FPS 游戏 1:1 复刻了一遍
前端
Penge6663 小时前
React Context 详解:从 Props 传递到跨组件状态共享
前端
Penge6663 小时前
React 事件处理:bind(this) 原理与实际开发常用写法
前端