当前位置:网站首页>Wangeditor rich text editor to upload pictures and solve cross-domain problems
Wangeditor rich text editor to upload pictures and solve cross-domain problems
2022-07-31 06:24:00 【God of data protection!】
I. Introduction
wangeditor rich text editor is a rich text editor developed by js and css, which is lightweight, concise and efficient
For more information, please check the official website: http://www.wangeditor.com/
Second, upload pictures
This chapter mainly talks about uploading pictures to the server using js language for saving
1. First stepCall the official website static resources2. Step 2const {createEditor,createToolbar}=window.wangEditor;//Create instance objectconst editorConfig={MENU_CONF:{},withCredentials:true,//Define this property as true to allow cross-domain accessautofocus: false,scroll: false,maxLength: 1200,minLength: 200,};editorConfig.MENU_CONF['uploadImage']={//This method is triggered when uploading or pasting an image to the editorfieldName:'image',server:'http://192.168.178.44:8888/upImage',//Background server addressmaxFileSize: 6 * 1024 * 1024, //maxNumberOfFiles: 200,// allowedFileTypes: ['image/*'],// timeout: 20 * 1000, // 5 seconds};When we upload an image on the front end, the editor will upload the image to the backend server for saving. My address is 'http://192.168.178.44:8888/upImage', and the return image address will be echoed on the editor.The returned data must start with the following structure (upload success, upload failure), otherwise an error will be reported.
{"errno": 0, // Note: the value is a number, not a string"data": {"url": "xxx", // image src , must"alt": "yyy", // image description text, not required"href": "zzz" // link to the image, not required}}{"errno": 1, // as long as not equal to 0"message": "Failure message"}Three, server-side method implementation
@[email protected]@RequestMapping(value = "/upImage")public Object upImage(MultipartFile image) {String filePath = "D:\\IntelliJ IDEA 2019.3.3\\IDEA project\\retry\\src\\main\\resources\\static\\picture\\";String suffix = "";try {String originalFilename = image.getOriginalFilename();if (originalFilename.contains(".")) {suffix = originalFilename.substring(originalFilename.lastIndexOf("."));}String fileName=System.currentTimeMillis()+suffix;File targetFile = new File(filePath, fileName);if(!targetFile.exists()){targetFile.createNewFile();}try {image.transferTo(targetFile);} finally {}String url="http://localhost:8888/static/"+fileName;JSONObject jsonObject=new JSONObject();JSONObject jsonObject1=new JSONObject();System.out.println(url);jsonObject1.put("url",url);jsonObject.put("errno",0);jsonObject.put("data",jsonObject1);return jsonObject;} catch (Exception e) {JSONObject jsonObject=new JSONObject();jsonObject.put("errno",1);jsonObject.put("message","failure information");return jsonObject;}}
The CrossOrigin annotation indicates that cross-domain access is allowed
Four. Test
A background service needs to be started to use the editor

Image pasted successfully!
Go to the server to check if the image exists locally


Frontier knowledge is not easy to make!
This concludes this chapter!Good luck to you all!
边栏推荐
- 钉钉企业内部-H5微应用开发
- Fluorescein-PEG-DSPE Phospholipid-Polyethylene Glycol-Fluorescein Fluorescent Phospholipid PEG Derivatives
- 数据分析之SQL面试真题
- Redis-Hash
- 机器学习和深度学习概述
- Markdown help documentation
- 2022年SQL大厂高频实战面试题(详细解析)
- opencv之图像二值化处理
- Cholesterol-PEG-Acid CLS-PEG-COOH Cholesterol-Polyethylene Glycol-Carboxyl Modified Peptides
- Podspec automatic upgrade script
猜你喜欢

CAS:1403744-37-5 DSPE-PEG-FA 科研实验用磷脂-聚乙二醇-叶酸

Cholesterol-PEG-Thiol CLS-PEG-SH Cholesterol-Polyethylene Glycol-Sulfhydryl

Sqlite column A data is copied to column B

机器学习和深度学习概述

为数学而歌之伯努利家族

科研试剂Cholesterol-PEG-Maleimide,CLS-PEG-MAL,胆固醇-聚乙二醇-马来酰亚胺

DC-CDN学习笔记

DSPE-PEG-COOH CAS:1403744-37-5 磷脂-聚乙二醇-羧基脂质PEG共轭物

活体检测CDCN学习笔记

pytorch学习笔记10——卷积神经网络详解及mnist数据集多分类任务应用
随机推荐
Embedding cutting-edge understanding
用pytorch里的children方法自定义网络
wangeditor编辑器内容传至后台服务器存储
Cholesterol-PEG-DBCO Cholesterol-Polyethylene Glycol-Diphenylcyclooctyne Chemical Reagent
mPEG-DMPE Methoxy-polyethylene glycol-bismyristyl phosphatidylethanolamine for stealth liposome formation
Flow control statement in js
Jupyter内核正忙、内核挂掉
Tensorflow——demo
DSPE-PEG-COOH CAS: 1403744-37-5 Phospholipid-polyethylene glycol-carboxy lipid PEG conjugate
Attention based ASR(LAS)
Nmap的下载与安装
opencv之访问图像像素的三种方法
拒绝采样小记
2022 SQL big factory high-frequency practical interview questions (detailed analysis)
[已解决]ssh连接报:Bad owner or permissions on C:\\Users/XXX/.ssh/config
Pytorch实现ResNet
Research reagents Cholesterol-PEG-Maleimide, CLS-PEG-MAL, Cholesterol-PEG-Maleimide
这些数组技巧,我爱了
ROS之service编程的学习和理解
Software Testing Interview Questions 2021