upload_avatar
POST
/api/v1/auth/profile/avatar/upload
const url = 'https://example.com/api/v1/auth/profile/avatar/upload';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'multipart/form-data'}};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}use reqwest;
#[tokio::main]pub async fn main() { let url = "https://example.com/api/v1/auth/profile/avatar/upload";
let form = reqwest::multipart::Form::new() .text("", ""); let mut headers = reqwest::header::HeaderMap::new(); headers.insert("Authorization", "Bearer <token>".parse().unwrap());
let client = reqwest::Client::new(); let response = client.post(url) .multipart(form) .headers(headers) .send() .await;
let results = response.unwrap() .json::<serde_json::Value>() .await .unwrap();
dbg!(results);}curl --request POST \ --url https://example.com/api/v1/auth/profile/avatar/upload \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: multipart/form-data'Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”Avatar image to upload
Media typemultipart/form-data
string
Responses
Section titled “Responses”Avatar uploaded
Media typeapplication/json
统一 API 响应格式
成功: { "code": "success", "msg": "", "data": {...} }
失败: { "code": "auth.credentials_failed", "msg": "Invalid Credentials" }
object
code
required
string
data
object
avatar
required
object
source
required
用户头像来源
string
url_1024
string | null
url_512
string | null
version
required
integer format: int32
display_name
string | null
error
msg
required
string
Example
{ "code": "success", "data": { "avatar": { "source": "none" } }}Invalid image upload
Not authenticated