13 changed files with 106 additions and 10 deletions
@ -0,0 +1,31 @@ |
|||||
|
package com.mathvision.diet.controller; |
||||
|
|
||||
|
import org.apache.commons.io.FileUtils; |
||||
|
import org.apache.commons.io.FilenameUtils; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Controller; |
||||
|
import org.springframework.util.Assert; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import java.nio.file.Paths; |
||||
|
|
||||
|
@RequestMapping("/icon") |
||||
|
@Controller |
||||
|
public class IconController extends BaseController { |
||||
|
|
||||
|
@Value(value = "${icon.path:icon}") |
||||
|
private String imagePath; |
||||
|
|
||||
|
@ResponseBody |
||||
|
@RequestMapping(method = RequestMethod.PUT) |
||||
|
public String addIngredient(@RequestParam MultipartFile file) throws Exception { |
||||
|
Assert.notNull(file, "[参数错误]请选择要上传的文件!"); |
||||
|
String fileName = String.format("%s.%s", System.currentTimeMillis(), FilenameUtils.getExtension(file.getOriginalFilename())); |
||||
|
FileUtils.copyInputStreamToFile(file.getInputStream(), Paths.get(imagePath, fileName).toFile()); |
||||
|
return fileName; |
||||
|
} |
||||
|
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,29 @@ |
|||||
|
<h1>图片部分</h1> |
||||
|
<h1>1. 上传图片</h1> |
||||
|
<blockquote> |
||||
|
<p>PUT /api/icon</p> |
||||
|
</blockquote> |
||||
|
<h3>输入:</h3> |
||||
|
<pre><code>Content-Type: multipart/form-data; boundary=boundary |
||||
|
|
||||
|
--boundary |
||||
|
Content-Disposition: form-data; name="file"; filename="xxx.jpg" |
||||
|
|
||||
|
< C:\Users\CCC\Documents\WeChat Files\wxid_40aqnb839lkd12\FileStorage\File\2023-09\xxx.jpg |
||||
|
|
||||
|
--boundary |
||||
|
Content-Disposition: form-data; name="extraInfo"; |
||||
|
</code></pre> |
||||
|
<h3>输出:</h3> |
||||
|
<pre><code>{ |
||||
|
"body": "1700415785530.jpg", |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
</code></pre> |
||||
|
<h1>2. 访问图片(挂在nginx目录下,不用通过api路径访问,使用前端路径访问)</h1> |
||||
|
<blockquote> |
||||
|
<p>GET /icon/12341234213.jpg</p> |
||||
|
</blockquote> |
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,31 @@ |
|||||
|
# 图片部分 |
||||
|
|
||||
|
# 1. 上传图片 |
||||
|
|
||||
|
> PUT /api/icon |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
Content-Type: multipart/form-data; boundary=boundary |
||||
|
|
||||
|
--boundary |
||||
|
Content-Disposition: form-data; name="file"; filename="xxx.jpg" |
||||
|
|
||||
|
< C:\Users\CCC\Documents\WeChat Files\wxid_40aqnb839lkd12\FileStorage\File\2023-09\xxx.jpg |
||||
|
|
||||
|
--boundary |
||||
|
Content-Disposition: form-data; name="extraInfo"; |
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"body": "1700415785530.jpg", |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
# 2. 访问图片(挂在nginx目录下,不用通过api路径访问,使用前端路径访问) |
||||
|
> GET /icon/12341234213.jpg |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue