当前位置:网站首页>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!
边栏推荐
- Cholesterol-PEG-Acid CLS-PEG-COOH Cholesterol-Polyethylene Glycol-Carboxyl Modified Peptides
- DSPE-PEG-COOH CAS:1403744-37-5 磷脂-聚乙二醇-羧基脂质PEG共轭物
- Cholesterol-PEG-Amine CLS-PEG-NH2 Cholesterol-Polyethylene Glycol-Amino Research Use
- Natural language processing related list
- DSPE-PEG-Azide DSPE-PED-N3 磷脂-聚乙二醇-叠氮脂质PFG
- cv2.imread()
- Jupyter内核正忙、内核挂掉
- pytorch模型微调finetuning训练image_dog(kaggle)
- 2022 SQL big factory high-frequency practical interview questions (detailed analysis)
- VS connects to MYSQL through ODBC (2)
猜你喜欢

Fluorescein-PEG-DSPE 磷脂-聚乙二醇-荧光素荧光磷脂PEG衍生物

CNN的一点理解

The browser looks for events bound or listened to by js

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

box-shadow相关属性

计算图像数据集均值和方差

MySQL 入门:Case 语句很好用

VS通过ODBC连接MYSQL(二)

Cholesterol-PEG-NHS NHS-PEG-CLS cholesterol-polyethylene glycol-active ester can modify small molecular materials

VS connects to MYSQL through ODBC (1)
随机推荐
拒绝采样小记
Pytorch常用函数
ROS之service编程的学习和理解
mPEG-DMPE Methoxy-polyethylene glycol-bismyristyl phosphatidylethanolamine for stealth liposome formation
活体检测CDCN学习笔记
cocos2d-x-3.2 create project method
Cholesterol-PEG-DBCO 胆固醇-聚乙二醇-二苯基环辛炔化学试剂
2021年软件测试面试题大全
关于Iframe
评估机器学习模型-摘抄
ERROR Error: No module factory availabl at Object.PROJECT_CONFIG_JSON_NOT_VALID_OR_NOT_EXIST ‘Error
pyspark.ml特征变换模块
使用 OpenCV 提取图像的 HOG、SURF 及 LBP 特征 (含代码)
钉钉H5微应用免登鉴权
Pytorch学习笔记13——Basic_RNN
Pytorch学习笔记09——多分类问题
解决background-size:cover时图片铺满但显示不完整?
Markdown help documentation
opencv之访问图像像素的三种方法
日志jar包冲突,及其解决方法