当前位置:网站首页>Upload pictures to the IIS server of this machine, and the results are returned in the form of web address, which can be accessed directly
Upload pictures to the IIS server of this machine, and the results are returned in the form of web address, which can be accessed directly
2022-07-22 15:35:00 【The way of dawn】
Configure this machine first iis The server , Search a lot of tutorials on the Internet
Control panel —— Procedures and functions —— Start or close winsows Program —— To configure Internet Information Services —— Select corresponding web Management tools and World Wide Web Services ——— Sure you can.
stay Windows You can see it in the management tool iis Open the software to configure .
Similar to this , Good configuration ip It can be used later ip Visit your folder directly to view pictures
java Background implementation
/**
* Upload picture file
*
* @return
*/
@RequestMapping("/uploadMdFiles")
@ResponseBody
public Result getContent(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile file, String topicCode) {
Map<String, Object> resultMap = new HashMap<>();
if (topicCode != null && !"".equals(topicCode)) {
// The CODE Used for storing corresponding pictures , The relationship between the article and the image needs to be stored in the actual project
System.out.println(" The theme CODE->" + topicCode);
}
try {
// Check whether there are uploaded files
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> multipartFileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entryFile : multipartFileMap.entrySet()) {
MultipartFile value = entryFile.getValue();
// Read the input stream
InputStream is = value.getInputStream();
// Get the file name
String fileName = value.getOriginalFilename();
// New file name , preservation
String newImageName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."), fileName.length());
// Statement byte Buffer array
byte[] b = new byte[(int) value.getSize()];
is.read(b);
// Upload the file name name As returned key, The default is file
resultMap.put(entryFile.getKey(), newImageName);
// Return interface call status code
resultMap.put("retCode", "success");
// Return to the image access path , This can be changed to OSS Distributed storage , Adjust according to the specific situation of the project
resultMap.put("rootPath", "http://192.168.109.34:8081/" + newImageName);
// Upload to file server path , Here I directly upload to the project deployment compilation path , Need to adjust
OutputStream os = new FileOutputStream(new File("H:\\IMAGEA", newImageName));
os.write(b);
os.flush();
}
}
} catch (Exception e) {
}
return Result.ok(resultMap);
}
Successful response cases :
{
"code": 200,
"message": " success ",
"data": {
"file": "20220720103728b095e433-4a41-4491-b431-ea74c194dc11.jpg",
"rootPath": "http://192.168.109.34:8081/20220720103728b095e433-4a41-4491-b431-ea74c194dc11.jpg",
"retCode": "success"
},
"ok": true
}
边栏推荐
- Still asking what to use for interface testing? Universal JMeter creates a performance test data platform
- Product banner style type analysis
- 卷妹的面试小抄每日更新Day1
- Add, delete, check and modify MySQL (second sentence)
- 用R写一个迷宫小游戏
- df.drop_duplicates() 详解+用法
- OUU益生菌精耕胃肠健康,获奖天猫国际微生态创新大会
- DM8: query the data file size limit of Dameng database
- Introduction to microservices
- Basic concept of Nacos and single machine startup
猜你喜欢
随机推荐
Kubernetes basic part learning notes
OpenSSL self signed certificate issuance script -- the road to building a dream
TDengine学习笔记
指数滑动平均法_百度百科
PLT draw and save the results
TDengine實驗集群搭建 Success
Cloud native ide: the first general and powerful codeless development platform of IVX
Tdengine learning notes
Summary of URL rules for real-time streaming of Hikvision, Dahua and yushila
海康、大华、宇视拉实时流url规则总结
[C language - program compilation] how does the line by line code get to an executable program step by step?
LeetCode 0814. 二叉树剪枝
深度学习之 8 深度模型优化与正则化
什么是探索性测试?探索性测试有哪些方法?
IO 和NIO的区别
Aidl summary
Autocomplete (autocomplete)
A simple inventory management system source code
92. (leaflet chapter) leaflet situation plotting - acquisition of attack direction
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or