图片上传
POST
/upload总之就是搞成form-data传过来,实例代码:
<input type="file" id="fileInput">
<button onclick="uploadFile()">Upload</button>
<div id="images">
</div>
<script>
function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if(!file) {
alert('Please select a file first.')
return;
}
const formData = new FormData();
formData.append('file', file);
axios.post('http://localhost:8080/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(response => {
console.log(response.data) ;
document.getElementById("images").innerHTML = "<img src='" + response.data.data + "'>";
}).catch(error => {
console.log(error) ;
});
}
</script>
请求参数
Header 参数
Authorization
string
JWT令牌
Body 参数multipart/form-data
image
file
必需
示例值:
file://D:\壁纸\斧乃木余接1.jpg
示例代码
返回响应
成功(200)
HTTP 状态码: 200
内容格式: JSONapplication/json
数据结构
code
integer
响应码
0-成功;1-失败
>= 0<= 1
message
string
响应信息
说明操作的结果
data
string | integer | boolean | array | object | number | null
响应数据
图片URL
示例
{
"code": 0,
"message": "string",
"data": "string"
}
修改于 4 个月前