MCPcopy Create free account
hub / github.com/Preloading/TwitterAPIBridge / UploadBlob

Function UploadBlob

bluesky/blueskyapi.go:2009–2034  ·  view source on GitHub ↗
(pds string, token string, data []byte, content_type string)

Source from the content-addressed store, hash-verified

2007}
2008
2009func 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//

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected