(c *stream.Client, cmd *cobra.Command, uploadtype uploadType, chType, chID, userID, filePath string)
| 24 | } |
| 25 | |
| 26 | func 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 | } |
no outgoing calls
no test coverage detected