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

Function uploadFileCmd

pkg/cmd/chat/file/file.go:20–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func uploadFileCmd() *cobra.Command {
21 cmd := &cobra.Command{
22 Use: "upload-file --channel-type [channel-type] --channel-id [channel-id] --user-id [user-id] --file [file]",
23 Short: "Upload a file",
24 Long: heredoc.Doc(`
25 Stream will not block any file types from uploading, however, different
26 clients may handle different types differently or not at all.
27 You can set a more restrictive list for your application if needed.
28 The maximum file size is 100MB.
29 Stream will allow any file extension. If you want to be more restrictive
30 for an application, this is can be set via API or by logging into your dashboard.
31 `),
32 Example: heredoc.Doc(`
33 # Uploads a file to 'redteam' channel of 'messaging' channel type
34 $ stream-cli chat upload-file --channel-type messaging --channel-id redteam --user-id "user-1" --file "./snippet.txt"
35 `),
36 RunE: func(cmd *cobra.Command, args []string) error {
37 c, err := config.GetConfig(cmd).GetClient(cmd)
38 if err != nil {
39 return err
40 }
41
42 chType, _ := cmd.Flags().GetString("channel-type")
43 chID, _ := cmd.Flags().GetString("channel-id")
44 user, _ := cmd.Flags().GetString("user-id")
45 file, _ := cmd.Flags().GetString("file")
46
47 path, err := utils.UploadFile(c, cmd, chType, chID, user, file)
48 if err != nil {
49 return err
50 }
51
52 cmd.Printf("Successfully uploaded file: %s\n", path)
53 return nil
54 },
55 }
56
57 fl := cmd.Flags()
58 fl.StringP("channel-type", "t", "", "[required] Channel type to interact with")
59 fl.StringP("channel-id", "i", "", "[required] Channel id to interact with")
60 fl.StringP("user-id", "u", "", "[required] User id")
61 fl.StringP("file", "f", "", "[required] File path")
62 _ = cmd.MarkFlagRequired("channel-type")
63 _ = cmd.MarkFlagRequired("channel-id")
64 _ = cmd.MarkFlagRequired("user-id")
65 _ = cmd.MarkFlagRequired("file")
66
67 return cmd
68}
69
70func uploadImageCmd() *cobra.Command {
71 cmd := &cobra.Command{

Callers 1

NewCmdsFunction · 0.85

Calls 3

GetConfigFunction · 0.92
UploadFileFunction · 0.92
GetClientMethod · 0.80

Tested by

no test coverage detected