(pds string, token string, data []byte, content_type string)
| 2007 | } |
| 2008 | |
| 2009 | func UploadBlob(pds string, token string, data []byte, content_type string) (*Blob, error) { |
| 2010 | url := pds + "/xrpc/com.atproto.repo.uploadBlob" |
| 2011 | |
| 2012 | resp, err := SendRequestWithContentType(&token, http.MethodPost, url, bytes.NewReader(data), content_type) |
| 2013 | if err != nil { |
| 2014 | return nil, err |
| 2015 | } |
| 2016 | defer resp.Body.Close() |
| 2017 | |
| 2018 | if resp.StatusCode != http.StatusOK { |
| 2019 | bodyBytes, _ := io.ReadAll(resp.Body) |
| 2020 | bodyString := string(bodyBytes) |
| 2021 | fmt.Println("Response Status:", resp.StatusCode) |
| 2022 | fmt.Println("Response Body:", bodyString) |
| 2023 | return nil, errors.New(bodyString) // return response |
| 2024 | } |
| 2025 | |
| 2026 | blob := struct { |
| 2027 | Blob Blob `json:"blob"` |
| 2028 | }{} |
| 2029 | if err := json.NewDecoder(resp.Body).Decode(&blob); err != nil { |
| 2030 | return nil, err |
| 2031 | } |
| 2032 | |
| 2033 | return &blob.Blob, nil |
| 2034 | } |
| 2035 | |
| 2036 | // Gets the URI components |
| 2037 | // |
nothing calls this directly
no test coverage detected