{"record":{"id":"55efd6e4468e6c5e","repo":"chenhg5/cc-connect","slug":"wecom-create-form-file-w","errorCode":null,"errorMessage":"wecom: create form file: %w","messagePattern":"wecom: create form file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/wecom.go","lineNumber":554,"sourceCode":"\tif result.ErrCode != 0 {\n\t\treturn fmt.Errorf(\"wecom: send image failed: %d %s\", result.ErrCode, result.ErrMsg)\n\t}\n\treturn nil\n}\n\n// uploadImageMedia uploads an image to WeChat Work media API and returns the media_id.\nfunc (p *Platform) uploadImageMedia(accessToken string, img core.ImageAttachment) (string, error) {\n\tname := img.FileName\n\tif name == \"\" {\n\t\tname = \"image.png\"\n\t}\n\n\tbody := &bytes.Buffer{}\n\twriter := multipart.NewWriter(body)\n\n\tpart, err := writer.CreateFormFile(\"media\", name)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"wecom: create form file: %w\", err)\n\t}\n\tif _, err := part.Write(img.Data); err != nil {\n\t\treturn \"\", fmt.Errorf(\"wecom: write image data: %w\", err)\n\t}\n\tif err := writer.Close(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"wecom: close multipart writer: %w\", err)\n\t}\n\n\tapiURL := p.wecomAPIURL(\"/cgi-bin/media/upload\", url.Values{\n\t\t\"access_token\": []string{accessToken},\n\t\t\"type\":         []string{\"image\"},\n\t})\n\tresp, err := p.apiClient.Post(apiURL, writer.FormDataContentType(), body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"wecom: upload image: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/wecom.go#L536-L572","documentation":"Wrap of multipart.Writer.CreateFormFile while building the image upload body in uploadImageMedia. Because the field name is the constant \"media\" and the destination is an in-memory bytes.Buffer, this error is practically unreachable — it is a defensive wrap required by the multipart API's error signature, not an expected runtime failure.","triggerScenarios":"Thrown at platform/wecom/wecom.go:554 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["No action needed in normal operation; if it ever fires, log it and abort the upload","The filename comes from img.FileName (defaulted to image.png); sanitize it if paranoid about header injection into the multipart part"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}