{"record":{"id":"6d2d19cb9222ef5b","repo":"JeffreySu/WeiXinMPSDK","slug":"jpg-jpeg-bmp-png","errorCode":null,"errorMessage":"商家名片会员图片仅支持 JPG、JPEG、BMP 或 PNG。","messagePattern":"商家名片会员图片仅支持 JPG、JPEG、BMP 或 PNG。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/BrandMemberCard/BrandMemberCardApis.cs","lineNumber":374,"sourceCode":"        }\n\n        private static void ValidateBrandMemberImageFileName(string fileName)\n        {\n            if (string.IsNullOrWhiteSpace(fileName))\n            {\n                throw new ArgumentException(\"文件名不能为空。\",\n                    nameof(fileName));\n            }\n\n            switch (Path.GetExtension(fileName)?.ToLowerInvariant())\n            {\n                case \".jpg\":\n                case \".jpeg\":\n                case \".bmp\":\n                case \".png\":\n                    return;\n                default:\n                    throw new ArgumentException(\n                        \"商家名片会员图片仅支持 JPG、JPEG、BMP 或 PNG。\",\n                        nameof(fileName));\n            }\n        }\n\n        private Task<T> PostAsync<T>(string path, object data, int timeOut)\n            where T : ReturnJsonBase, new()\n        {\n            return _request.RequestAsync<T>(GetUrl(path), data, timeOut);\n        }\n\n        private Task<T> PatchAsync<T>(string path, object data, int timeOut)\n            where T : ReturnJsonBase, new()\n        {\n            return _request.RequestAsync<T>(GetUrl(path), data, timeOut,\n                ApiRequestMethod.PATCH);\n        }\n","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/BrandMemberCard/BrandMemberCardApis.cs#L356-L392","documentation":"WeChat's brand member card image upload only accepts JPG, JPEG, BMP, and PNG images. ValidateBrandMemberImageFileName inspects the fileName extension (case-insensitive) and throws ArgumentException for any other extension, preventing a guaranteed-to-fail upload.","triggerScenarios":"Calling UploadMemberImageAsync with a file name whose extension is .gif, .webp, .heic, .tiff, or has no extension at all.","commonSituations":"Users uploading modern formats (WebP/HEIC) from phones; server-side transcoding pipelines passing original names; file names generated without extensions.","solutions":["Convert the image to JPG or PNG before upload (e.g. via SkiaSharp/ImageSharp).","Validate and normalize the extension in your own pipeline before calling the API.","Rename the file to include a supported extension only when the actual format matches — never just rename a GIF to .png."],"exampleFix":"// before\nawait apis.UploadMemberImageAsync(brandId, bytes, \"avatar.webp\");\n// after\nvar pngBytes = ImageConversion.ConvertToPng(bytes); // transcode first\nawait apis.UploadMemberImageAsync(brandId, pngBytes, \"avatar.png\");","handlingStrategy":"validation","validationCode":"var ext = Path.GetExtension(fileName)?.ToLowerInvariant();\nif (ext is not (\".jpg\" or \".jpeg\" or \".bmp\" or \".png\"))\n    throw new ArgumentException(\"Member images must be JPG, JPEG, BMP or PNG.\");","typeGuard":"bool supportedImage(string? f) =>\n    Path.GetExtension(f ?? \"\")?.ToLowerInvariant() is \".jpg\" or \".jpeg\" or \".bmp\" or \".png\";","tryCatchPattern":"try { await apis.UploadMemberImageAsync(brandId, bytes, fileName); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"JPG\")) { return ConvertToJpg(bytes); }","preventionTips":["Transcode uploads (WebP/HEIC) to JPG/PNG server-side before any WeChat upload","Restrict the file picker accept attribute to .jpg,.jpeg,.bmp,.png","Validate the extension early in the upload pipeline"],"tags":["image-upload","unsupported-format","validation"],"backgroundTag":"unsupported-enum-value","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}