当前位置:网站首页>3. Upload the avatar to qiniu cloud and display it
3. Upload the avatar to qiniu cloud and display it
2022-07-26 02:06:00 【A snicker】
In settings , change the avatar , Upload to qiniuyun , And display a new avatar .
controller:
@LoginRequired
@GetMapping("/setting")
public String getSettingPage(Model model) {
// Upload file name
String fileName = CommunityUtil.generateUUID();
// Set response information
StringMap policy = new StringMap();
policy.put("returnBody", CommunityUtil.getJSONString(0));
// Generate upload credentials
Auth auth = Auth.create(accessKey, secretKey);
String uploadToken = auth.uploadToken(headerBucketName, fileName, 3600, policy);
model.addAttribute("uploadToken", uploadToken);
model.addAttribute("fileName", fileName);
return "site/setting";
}
front end : When you click Submit Form , from JQuery Asynchronously transmit the data to the ECS according to the setting information ( That is, the client uploads to the ECS ). Uploading successfully will update the image path
js:
$(function () {
$("#uploadForm").submit(upload);
$("#forgetForm").submit(forget);
});
function upload() {
$.ajax({
url:
"http://up-z1.qiniup.com",
method:
"post",
processData:
false,
contentType:
false,
data:
new FormData($("#uploadForm")[0]),
success: function (data) {
if (data && data.code == 0) {
// Update avatar path
$.post(
CONTEXT_PATH + "/user/header/url",
{
"fileName": $("input[name='key']").val()},
function (data) {
data = $.parseJSON(data);
if (data.code == 0) {
window.location.reload();
} else {
alert(data.msg);
}
}
);
} else {
alert(" Upload failed !");
}
}
})
;
return false;
}
Update the avatar path in the database :
@PostMapping("/header/url")
@ResponseBody
public String updateHeaderUrl(String fileName) {
if (StringUtils.isBlank(fileName)) {
return CommunityUtil.getJSONString(1, " File name cannot be empty ");
}
String url = headerBucketUrl + "/" + fileName;
int id = hostHolder.getUser().getId();
userService.updateHeader(hostHolder.getUser().getId(), url);
return CommunityUtil.getJSONString(0);
}
边栏推荐
- Jupiter notebook reported an error: notebook validation failed: non unique cell ID '2a4xx6' detected
- Composition API的优势
- Redis6.x配置参数详解
- SQLyog数据导入导出图文教程
- I.MX6UL核心模块使用连载-TF卡读写测试 (五)
- Implementation of C iterator
- Postman报Json序列化错误
- 转:高效做正确的事
- TI AM335x工控模块网络跟文件系统NFS的实现
- These practical security browser plug-ins improve your efficiency
猜你喜欢

Protect syslog servers and devices

Why does the debugger display the wrong function

The slow loading of the first entry page of vite local operation

1. Mx6ul core module use serial RTC test (XII)

1. Mx6ul core module serial use - touch screen calibration (IX)

1. Mx6ul core module serial WiFi test (VIII)

BGP知识点总结

Qt程序美化之样式表的使用方法,Qt使用图片作为背景与控件透明化,Qt自定义按钮样式

餐饮连锁门店重塑增长背后的数字化转型

SQL manual blind injection and error reporting injection
随机推荐
excel中怎么显示数字/英文时间
Build embedded development environment and FRP penetration under win
Redis集群搭建(基于6.x)
MPLS知识点
Guys, the flinksql datahub source table has a field timestamp 16 bits, which is written to ora
Protect syslog servers and devices
转:高效做正确的事
pdf. JS introduction
i. Mx6ull snvs power domain GPIO status hold verification
【独立站建设】shopify卖家:学会这几点,网上商店销量翻倍!
Detailed explanation of redis6.x configuration parameters
D. Rating compression (thinking + double pointer)
1205 Lock wait timeout exceeded; try restarting transaction处理
Turn: do the right thing efficiently
登堂入室soc之编程基础环境变量设置
Video game quiz? I think it's useless. It's better to do these well!
Implementation of C iterator
How idea can quickly delete recently opened projects
AttributeError: ‘Document‘ object has no attribute ‘pageCount‘
Republishing foundation and configuration