{"record":{"id":"87fb7468d4dc6417","repo":"flipped-aurora/gin-vue-admin","slug":"function-formuploader-put-failed-err-87fb74","errorCode":null,"errorMessage":"function formUploader.Put() failed, err:","messagePattern":"function formUploader\\.Put\\(\\) failed, err:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/upload/qiniu.go","lineNumber":49,"sourceCode":"\tmac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)\n\tupToken := putPolicy.UploadToken(mac)\n\tcfg := qiniuConfig()\n\tformUploader := storage.NewFormUploader(cfg)\n\tret := storage.PutRet{}\n\tputExtra := storage.PutExtra{Params: map[string]string{\"x:name\": \"github logo\"}}\n\n\tf, openError := file.Open()\n\tif openError != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(openError).Error(\"function file.Open() failed\")\n\n\t\treturn \"\", \"\", errors.New(\"function file.Open() failed, err:\" + openError.Error())\n\t}\n\tdefer f.Close()                                                  // 创建文件 defer 关闭\n\tfileKey := fmt.Sprintf(\"%d%s\", time.Now().Unix(), file.Filename) // 文件名格式 自己可以改 建议保证唯一性\n\tputErr := formUploader.Put(context.Background(), &ret, upToken, fileKey, f, file.Size, &putExtra)\n\tif putErr != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(putErr).Error(\"function formUploader.Put() failed\")\n\t\treturn \"\", \"\", errors.New(\"function formUploader.Put() failed, err:\" + putErr.Error())\n\t}\n\treturn global.GVA_CONFIG.Qiniu.ImgPath + \"/\" + ret.Key, ret.Key, nil\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@author: [ccfish86](https://github.com/ccfish86)\n//@author: [SliverHorn](https://github.com/SliverHorn)\n//@object: *Qiniu\n//@function: DeleteFile\n//@description: 删除文件\n//@param: key string\n//@return: error\n\nfunc (*Qiniu) DeleteFile(ctx context.Context, key string) error {\n\tbucketManager := newBucketManager()\n\tif err := bucketManager.Delete(global.GVA_CONFIG.Qiniu.Bucket, key); err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function bucketManager.Delete() failed\")\n\t\treturn errors.New(\"function bucketManager.Delete() failed, err:\" + err.Error())","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/upload/qiniu.go#L31-L67","documentation":"The Qiniu formUploader.Put call failed while uploading the opened file to the Qiniu Kodo bucket with the upload token. This wraps the qiniu-sdk-go error — which may be token invalid/expired, bucket mismatch, network failure, or a Qiniu API rejection. The returned message embeds putErr.Error() after the prefix.","triggerScenarios":"Calling Qiniu.UploadFile when formUploader.Put returns an error: invalid or expired upload token (bad AccessKey/SecretKey), bucket name mismatch, key policy violation, network/DNS failure to Qiniu upload hosts, or file size/policy limits exceeded.","commonSituations":"Wrong qiniu access-key/secret-key in config.yaml, bucket renamed or deleted, server clock skew invalidating tokens, firewall egress blocking Qiniu upload endpoints, putting to a bucket in a different zone than the configured Zone.","solutions":["Check the embedded putErr text — Qiniu errors carry codes like 'bad token' or 'no such bucket' that pinpoint the cause.","Verify qiniu access-key, secret-key, bucket, and zone settings in config.yaml against the Qiniu console.","Regenerate keys if rotated; ensure server time is NTP-synced for token validity.","Confirm egress network access from the server to Qiniu upload endpoints.","Ensure the bucket name in Put matches the token's putPolicy scope exactly."],"exampleFix":"// before\nputErr := formUploader.Put(context.Background(), &ret, upToken, fileKey, f, file.Size, &putExtra)\n// after — make the zone explicit so Put hits the right region\nzone := &storage.ZoneHuadong\ncfg := storage.Config{Zone: zone, UseHTTPS: false, UseCdnDomains: false}\nformUploader := storage.NewFormUploader(&cfg)","handlingStrategy":"try-catch","validationCode":"if global.GVA_CONFIG.Qiniu.AccessKey == \"\" || global.GVA_CONFIG.Qiniu.SecretKey == \"\" || global.GVA_CONFIG.Qiniu.Bucket == \"\" {\n    return errors.New(\"qiniu config incomplete\")\n}","typeGuard":null,"tryCatchPattern":"path, key, err := q.UploadFile(ctx, fileHeader)\nif err != nil {\n    if strings.Contains(err.Error(), \"bad token\") || strings.Contains(err.Error(), \"no such bucket\") {\n        logger.Error(\"qiniu misconfigured: %v\", err) // config problem, alert ops\n    } else {\n        logger.Error(\"qiniu transient failure: %v\", err) // candidate for retry\n    }\n    c.JSON(500, gin.H{\"code\": 7, \"msg\": \"上传失败，请稍后重试\"})\n}","preventionTips":["Verify AccessKey/SecretKey/Bucket/Zone against the Qiniu console after key rotation.","NTP-sync server clocks so upload tokens stay valid.","Configure an explicit storage zone matching the bucket region.","Test egress connectivity to Qiniu upload endpoints from production hosts."],"tags":["qiniu","upload","object-storage","token"],"backgroundTag":"qiniu-put-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}