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

Function uploadImageCmd

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

Source from the content-addressed store, hash-verified

68}
69
70func uploadImageCmd() *cobra.Command {
71 cmd := &cobra.Command{
72 Use: "upload-image --channel-type [channel-type] --channel-id [channel-id] --user-id [user-id] --file [file] --content-type [content-type]",
73 Short: "Upload an image",
74 Long: heredoc.Doc(`
75 Stream supported image types are: image/bmp, image/gif, image/jpeg, image/png,
76 image/webp, image/heic, image/heic-sequence, image/heif, image/heif-sequence,
77 image/svg+xml.
78 You can set a more restrictive list for your application if needed.
79 The maximum file size is 100MB.
80 Stream will allow any file extension. If you want to be more restrictive
81 for an application, this is can be set via API or by logging into your dashboard.
82 `),
83 Example: heredoc.Doc(`
84 # Uploads an image to 'redteam' channel of 'messaging' channel type
85 $ stream-cli chat upload-image --channel-type messaging --channel-id redteam --user-id "user-1" --file "./picture.png" --content-type "image/png"
86 `),
87 RunE: func(cmd *cobra.Command, args []string) error {
88 c, err := config.GetConfig(cmd).GetClient(cmd)
89 if err != nil {
90 return err
91 }
92
93 chType, _ := cmd.Flags().GetString("channel-type")
94 chID, _ := cmd.Flags().GetString("channel-id")
95 user, _ := cmd.Flags().GetString("user-id")
96 file, _ := cmd.Flags().GetString("file")
97
98 path, err := utils.UploadImage(c, cmd, chType, chID, user, file)
99 if err != nil {
100 return err
101 }
102
103 cmd.Printf("Successfully uploaded image: %s\n", path)
104 return nil
105 },
106 }
107
108 fl := cmd.Flags()
109 fl.StringP("channel-type", "t", "", "[required] Channel type to interact with")
110 fl.StringP("channel-id", "i", "", "[required] Channel id to interact with")
111 fl.StringP("user-id", "u", "", "[required] User id")
112 fl.StringP("file", "f", "", "[required] Image file path")
113 _ = cmd.MarkFlagRequired("channel-type")
114 _ = cmd.MarkFlagRequired("channel-id")
115 _ = cmd.MarkFlagRequired("user-id")
116 _ = cmd.MarkFlagRequired("file")
117
118 return cmd
119}
120
121func deleteFileCmd() *cobra.Command {
122 cmd := &cobra.Command{

Callers 1

NewCmdsFunction · 0.85

Calls 3

GetConfigFunction · 0.92
UploadImageFunction · 0.92
GetClientMethod · 0.80

Tested by

no test coverage detected