Files
photography/backend/test_avatar_upload.http
xujiang fa5f7a0ed2 feat: 实现用户头像上传功能
- 创建头像上传API接口 (POST /api/v1/users/:id/avatar)
- 实现完整的头像上传逻辑,包含权限验证和文件处理
- 添加头像图片处理功能,支持自动压缩和居中裁剪
- 完善静态文件服务,支持头像访问
- 创建完整的API测试用例
- 更新任务进度文档

任务11已完成,项目完成率提升至37.5%
2025-07-11 13:10:04 +08:00

98 lines
3.1 KiB
HTTP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

###
### 1. Token
POST {{host}}/api/v1/auth/login
Content-Type: application/json
{
"username": "admin",
"password": "admin123"
}
### 2. ()
POST {{host}}/api/v1/users/1/avatar
Authorization: Bearer {{token}}
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="avatar"; filename="avatar.jpg"
Content-Type: image/jpeg
< ./test_images/avatar.jpg
------WebKitFormBoundary7MA4YWxkTrZu0gW--
### 3. - ()
POST {{host}}/api/v1/users/1/avatar
Authorization: Bearer {{token}}
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="avatar"; filename="large_image.jpg"
Content-Type: image/jpeg
< ./test_images/large_image.jpg
------WebKitFormBoundary7MA4YWxkTrZu0gW--
### 4. - ()
POST {{host}}/api/v1/users/1/avatar
Authorization: Bearer {{token}}
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="avatar"; filename="document.txt"
Content-Type: text/plain
This is not an image file
------WebKitFormBoundary7MA4YWxkTrZu0gW--
### 5. - ()
POST {{host}}/api/v1/users/1/avatar
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="avatar"; filename="avatar.jpg"
Content-Type: image/jpeg
< ./test_images/avatar.jpg
------WebKitFormBoundary7MA4YWxkTrZu0gW--
### 6. - ()
POST {{host}}/api/v1/users/999/avatar
Authorization: Bearer {{token}}
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="avatar"; filename="avatar.jpg"
Content-Type: image/jpeg
< ./test_images/avatar.jpg
------WebKitFormBoundary7MA4YWxkTrZu0gW--
### 7. URL
GET {{host}}/api/v1/users/1
Authorization: Bearer {{token}}
### 8. 访
GET {{host}}/uploads/avatars/avatar_1_1641234567_150x150.jpg
###
@host = http://localhost:8080
@token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
###
# 1. test_images
# 2.
# - test_images/avatar.jpg (, < 5MB)
# - test_images/large_image.jpg (5MB)
# 3. {{token}} JWT
# 4. IDID
###
# 1. 200 URL
# 2. 400
# 3. 400
# 4. 401
# 5. 403
# 6. uploads/avatars/
# 7. (150x150)
# 8. avatar URL