()
| 68 | } |
| 69 | |
| 70 | func 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 | |
| 121 | func deleteFileCmd() *cobra.Command { |
| 122 | cmd := &cobra.Command{ |
no test coverage detected