上一章实现在word在线预览,下一步实现
  1. 在线编辑,保存到服务器。
  2. 创建数据源,为用户提供占位符
在上一步的配置项中有callbackUrl: 'http://IP/api/v1/onlyoffice/callback'这个url就是在word保存后的回调地址,如果设置了这个地址,需要保证only office服务器能能正常访问这个地址。

这里说的保存是指保存到了only office服务器,而我们需要的是保存到上一步中document.url中指向的地址,也就是minio服务器。
默认情况下
在页面刚打开时only office就会调用这个callbackUrl
当我们关闭编辑窗口后,十秒钟左右onlyoffice会调用这个callbackUrl

不同的状态下调用callbackUrl会以josn格式提交不同的参数,详细参数参考【Callback param

其中有两个重要的参数1.status
页面打开时status=1表示开始编辑,这时需要接口返回约定格式的字符串{"error":0},只有这样返回,onlyoffice服务器才会判定当前callbackUrl是可用的。否则会报异常。
这份文件无法保存。请检查连接设置或联系您的管理员。当您点击"OK"按钮,系统会提示您下载文档。


在status=2或3时,可以获取url也就是更新后的文档的 url,可以从这个url下载最新文档,然后提交到minio服务器
status状态说明:
1 - document is being edited,
2 - document is ready for saving,
3 - document saving error has occurred,
4 - document is closed with no changes,
6 - document is being edited, but the current document state is saved,
7 - error has occurred while force saving the document.
Status 1 is received every user connection to or disconnection from
document co-editing. His callbackUrl is used.
Status 2 (3) is received 10 seconds after the document is closed for
editing with the identifier of the user who was the last to send the
changes to the document editing service. The callbackUrl from the user
who made the last changes to the file is used.
Status 4 is received after the document is closed for editing with no
changes by the last user. His callbackUrl is used.
Status 6 (7) is received when the force saving request is performed.
The callbackUrl from the user who made the last changes to the file is
used.
大概流程如下:
DataRow param = DataRow.parseJon(WebUtil.read(HttpServletRequest));
int status = param.getInt("status",0);

String cache_url = tmp.getString("url");  //编辑后文件地址 //http://onlyoffice服务地址/cache/files/data/13be3b24761275750c95_6269/output.docx/output.docx?md5=Mb91G18BYA8-ciPyjqrmiA&expires=1694653054&filename=output.docx
if(status==2 || status== 3){
	if(BasicUtil.isNotEmpty(cache_url)){
		MinioUtil util = MinioUtil.getInstance();
		//如果有需要,可以下载到服务器本地
		File newFile = new File(BasicUtil.getRandomLowerString(16));
		HttpUtil.download(cache_url, newFile);
		util.putObject(minio_path, newFile);
		newFile.delete();
		//一般不需要直接上传到minio服务器即可
		util.putObject(minio_path, HttpUtil.stream(cache_url).getInputStream());
	}
}
这样就实现了文档的在线预览和编辑,下一步进入业务逻辑【数据源与占位符