mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [netutil] handle upload responses (#389)
This commit is contained in:
1 parent
febd1030af
commit
be9b167a9b
2 files changed
+46
-1
No files matched your search
+5
-1
@@ -269,10 +269,14 @@ func UploadFile(filepath string, server string) (bool, error) {
|
||||
contentType := writer.FormDataContentType()
|
||||
writer.Close()
|
||||
|
||||
_, err = http.Post(server, contentType, bodyBuffer)
|
||||
resp, err := http.Post(server, contentType, bodyBuffer)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
||||
return false, fmt.Errorf("upload failed: %s", resp.Status)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user