MCPcopy Index your code
hub / github.com/coder/coder / UploadChatFile

Method UploadChatFile

codersdk/chats.go:3278–3294  ·  view source on GitHub ↗

UploadChatFile uploads a file for use in chat messages.

(ctx context.Context, organizationID uuid.UUID, contentType string, filename string, rd io.Reader)

Source from the content-addressed store, hash-verified

3276
3277// UploadChatFile uploads a file for use in chat messages.
3278func (c *ExperimentalClient) UploadChatFile(ctx context.Context, organizationID uuid.UUID, contentType string, filename string, rd io.Reader) (UploadChatFileResponse, error) {
3279 res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/experimental/chats/files?organization=%s", organizationID), rd, func(r *http.Request) {
3280 r.Header.Set("Content-Type", contentType)
3281 if filename != "" {
3282 r.Header.Set("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": filename}))
3283 }
3284 })
3285 if err != nil {
3286 return UploadChatFileResponse{}, err
3287 }
3288 defer res.Body.Close()
3289 if res.StatusCode != http.StatusCreated {
3290 return UploadChatFileResponse{}, ReadBodyAsError(res)
3291 }
3292 var resp UploadChatFileResponse
3293 return resp, json.NewDecoder(res.Body).Decode(&resp)
3294}
3295
3296// GetChatFile retrieves a previously uploaded chat file by ID.
3297func (c *ExperimentalClient) GetChatFile(ctx context.Context, fileID uuid.UUID) ([]byte, string, error) {

Callers 6

TestPostChatFileFunction · 0.95
TestGetChatFunction · 0.80
TestChatMessageWithFilesFunction · 0.80
TestPatchChatMessageFunction · 0.80
TestGetChatFileFunction · 0.80

Calls 4

ReadBodyAsErrorFunction · 0.85
SetMethod · 0.65
CloseMethod · 0.65
RequestMethod · 0.45

Tested by 6

TestPostChatFileFunction · 0.76
TestGetChatFunction · 0.64
TestChatMessageWithFilesFunction · 0.64
TestPatchChatMessageFunction · 0.64
TestGetChatFileFunction · 0.64