Based on the document online editing ability of Yongzhong WebOffice, users can use it Cloud editing service You can edit the document directly on the web page, save the modified content in real time, and restore to any historical version according to the file version id.
First, become a developer and apply for an application. On the homepage of Yongzhong cloud service platform( https://open.yozocloud.cn )Click "apply for adding" to fill in the information and submit it. Then click "management center" in the upper right corner of the page, click "apply for adding a new application" to apply for an application, and then you will get the appId and appKey in the figure below.
Then read Cloud edit development document The development document on the official website contains all the interfaces to be used in editing, and gives return examples for reference. It also summarizes the common problems encountered in the process of use.
The following are the specific access steps:
Step 1: import the jar package to generate a signature. The official website provides SDKs for several popular programming languages. Download the corresponding SDK and demo according to your own development language to generate a signature. JAVA SDK is used here.
SDK download address: https://cms.yozocloud.cn/info/file/getResource/81
DEMO download address: https://cms.yozocloud.cn/info/file/getResource/82
public static String APPID = "XXXX"; public static String APPKEY = "XXXXXX"; public static String EDITFILE = "XXXXXX"; /** * Get signature information * * @param map Parameter k-v * @return autograph * @throws Exception abnormal */ String getSign(Map<String,String[]> map) throws Exception { map.put("appId",new String[]{APPID}); AppAuthenticator authenticator=new UaaAppAuthenticator(UaaConstant.SIGN,null,UaaConstant.APPID); String sign = authenticator.generateSign(APPKEY, map); System.out.println("sign = " + sign); return sign; }
Step 2: upload a file. Here I use RestTemplate to send a Post request. Note that when uploading a file, the file type must be multipartFile, otherwise an error will be reported: message: unknown server error ^ ^.
Map<String, String[]> params = new HashMap<>(); String sign = getSign(params); String url = "http://dmc.yozocloud.cn/api/file/upload?appId={0}&sign={1}"; url = url.replace("{0}", APPID).replace("{1}", sign); System.out.println("url:" + url); //Upload file String filePath = "C:"; String fileName = "11111.xlsx"; //Set request header HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("multipart/form-data"));//The file type is multipartFile //Set the request body. Note that it is LinkedMultiValueMap FileSystemResource fileSystemResource = new FileSystemResource(filePath + "/" + fileName); MultiValueMap<String, Object> form = new LinkedMultiValueMap<>(); form.add("file", fileSystemResource); RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(form, headers), String.class);//Prevent the return information from being garbled System.out.println("The returned information is: " + response.getBody());//Get return information
Step 3: get the edit address. Each time you call the interface, use these parameters to generate a sign, except multipartFile. Do not pass null or empty string for unused parameters.
JSONObject data = JSONObject.parseObject(response.getBody()).getJSONObject("data"); String fileVersionId = data.getString("fileVersionId");//Gets the returned fileVersionId Map<String, String[]> paramMap = new HashMap<>(); paramMap.put("fileVersionId", new String[]{fileVersionId}); String s = getSign(paramMap);//Generate signature System.out.println("Edit address:" + DEITFILE + "?appId=" + APPID + "&fileVersionId=" + fileVersionId + "&sign=" + s);//Get edit address
Finally, run the program to get the edit address.
The following is a comparison between source documents and documents edited using cloud:
Source document:
Cloud editing:
be careful:
1. The user must fill in the correct data callback address in the development information edited by the cloud to receive the new file version id, and add a POST interface under the data callback URL. The interface name is set to: / 3rd/edit/callBack. The code example of the interface receiving and converting callback data is as follows:
2. Cloud editing is saved in real time. If you close the editing page or do not operate on the editing page for 30 minutes, a callback will be triggered;
3. Cloud editing does not support multi person collaboration. If you can view the document while editing, you can use the parameter "autoReader=true" to control read-only, but the viewed document is the document before editing, and you can't see the content edited in real time;
4. When accessing the editing page, you can directly access the splicing address. If you access the redirection link, you will be prompted "join editing failed, you do not have permission to edit this document or the session has expired".