MCPcopy Create free account
hub / github.com/GetStream/stream-cli / uploadFile

Function uploadFile

pkg/cmd/chat/utils/fileupload.go:26–52  ·  view source on GitHub ↗
(c *stream.Client, cmd *cobra.Command, uploadtype uploadType, chType, chID, userID, filePath string)

Source from the content-addressed store, hash-verified

24}
25
26func uploadFile(c *stream.Client, cmd *cobra.Command, uploadtype uploadType, chType, chID, userID, filePath string) (string, error) {
27 file, err := os.Open(filePath)
28 if err != nil {
29 return "", err
30 }
31 defer file.Close()
32
33 req := stream.SendFileRequest{
34 User: &stream.User{ID: userID},
35 FileName: filepath.Base(file.Name()),
36 Reader: file,
37 }
38
39 var resp *stream.SendFileResponse
40
41 if uploadtype == uploadTypeImage {
42 resp, err = c.Channel(chType, chID).SendImage(cmd.Context(), req)
43 } else {
44 resp, err = c.Channel(chType, chID).SendFile(cmd.Context(), req)
45 }
46
47 if err != nil {
48 return "", err
49 }
50
51 return resp.File, nil
52}

Callers 2

UploadFileFunction · 0.85
UploadImageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected