文件上传
[TOC]
# [附属]
## 1. 单个文件上传
#### 接口
```
/upload/file
```
#### 接口功能
> 文件单个
|参数|必选|类型|说明|
|:----- |:-------|:-----|:-----|
|file|ture|File|单个文件对象|
#### 请求方式
> POST
###### 请求例子
```
curl -X POST \
http://localhost:8096/upload/file \
-H 'Postman-Token: 195e0dd2-65ec-4411-bd0b-6f2e81e56e1b' \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F 'file=@C:\Users\EDZ\Pictures\Saved Pictures\timg (1).jpg'
jquery 例子
var form = new FormData();
form.append("file", "C:\\Users\\EDZ\\Pictures\\Saved Pictures\\timg (1).jpg");
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:8096/upload/file",
"method": "POST",
"headers": {
"cache-control": "no-cache",
"Postman-Token": "12f09ae7-25d5-4a98-994c-c381e871df17"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}
$.ajax(settings).done(function (response) {
console.log(response);
});
```
###### 返回结果
```
{
"status": 200,
"message": "",
"error": "",
"error_description": "",
"timestamp": "1597735481906",
"operator": "张文",
"data": {
"path": "http://localhost:8096/file/20200818/132f29aa-e065-4da5-a8e0-ac931cfaa73f.jpg"
}
}
```
## 2. 多个文件上传
#### 接口
```
/upload/files
```
#### 请求方式
> POST
#### 接口功能
> 流程流程
|参数|必选|类型|说明|
|:----- |:-------|:-----|:-----|
|files|ture|File|文件对象数组|
###### 请求例子
```
curl -X POST \
http://localhost:8096/upload/files \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Postman-Token: de5043e0-babc-4883-b5e1-aff4e344cbb2' \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F 'files=@C:\Users\EDZ\Pictures\Saved Pictures\timg (2).jpg' \
-F 'files=@C:\Users\EDZ\Pictures\Saved Pictures\timg.jpg'
jquery 例子
var form = new FormData();
form.append("files", "C:\\Users\\EDZ\\Pictures\\Saved Pictures\\timg (2).jpg");
form.append("files", "C:\\Users\\EDZ\\Pictures\\Saved Pictures\\timg.jpg");
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:8096/upload/files",
"method": "POST",
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}
$.ajax(settings).done(function (response) {
console.log(response);
});
```
###### 返回结果
```
{
"status": 200,
"message": "",
"error": "",
"error_description": "",
"timestamp": "1597735296032",
"operator": "张文",
"data": [
{
"result": "ok",
"originalFileName": "timg (2).jpg",
"path": "http://localhost:8096/file/20200818/109777ae-6e6a-4899-8471-094d8ea718e8.jpg"
},
{
"result": "ok",
"originalFileName": "timg.jpg",
"path": "http://localhost:8096/file/20200818/3d59cf0d-d097-4ae2-8ac1-aa057b075349.jpg"
}
]
}
```