{"record":{"id":"c5432bdf7eeda9a8","repo":"flipped-aurora/gin-vue-admin","slug":"minio-err","errorCode":null,"errorMessage":"上传文件到minio失败, err:","messagePattern":"上传文件到minio失败, err:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/upload/minio_oss.go","lineNumber":87,"sourceCode":"\t} else {\n\t\tfilePathres = global.GVA_CONFIG.Minio.BasePath + \"/\" + time.Now().Format(\"2006-01-02\") + \"/\" + filename\n\t}\n\n\t// 根据文件扩展名检测 MIME 类型\n\tcontentType := mime.TypeByExtension(ext)\n\tif contentType == \"\" {\n\t\tcontentType = \"application/octet-stream\"\n\t}\n\n\t// 设置超时10分钟\n\tputCtx, cancel := context.WithTimeout(ctx, time.Minute*10)\n\tdefer cancel()\n\n\t// Upload the file with PutObject   大文件自动切换为分片上传\n\tinfo, err := client.PutObject(putCtx, global.GVA_CONFIG.Minio.BucketName, filePathres, &filecontent, file.Size, minio.PutObjectOptions{ContentType: contentType})\n\tif err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"上传文件到minio失败\")\n\t\treturn \"\", \"\", errors.New(\"上传文件到minio失败, err:\" + err.Error())\n\t}\n\treturn global.GVA_CONFIG.Minio.BucketUrl + \"/\" + info.Key, filePathres, nil\n}\n\nfunc (m *Minio) DeleteFile(ctx context.Context, key string) error {\n\tclient, err := newMinioClient()\n\tif err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"minio client 初始化失败\")\n\t\treturn errors.New(\"minio client 初始化失败, err:\" + err.Error())\n\t}\n\n\tdelCtx, cancel := context.WithTimeout(ctx, time.Second*5)\n\tdefer cancel()\n\n\t// Delete the object from MinIO\n\terr = client.RemoveObject(delCtx, global.GVA_CONFIG.Minio.BucketName, key, minio.RemoveObjectOptions{})\n\treturn err\n}","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/upload/minio_oss.go#L69-L105","documentation":"This error wraps any failure returned by the minio-go client's PutObject call when uploading a file to a MinIO (or S3-compatible) bucket. The library throws it because the object PUT request failed — the client was constructed fine, but the transfer itself errored (network, bucket, permissions, size, or context timeout). The message embeds the underlying minio error text after the prefix.","triggerScenarios":"Calling Minio.UploadFile when PutObject returns an error: bucket does not exist, credentials lack s3:PutObject, connection to endpoint refused/timeout (putCtx has a 5s timeout), network interruption mid-transfer, or object name (filePathres) invalid.","commonSituations":"Bucket name typo in config.yaml (minio.bucket-name), MinIO server down or unreachable from the app host, read-only access key, Docker network isolation, files larger than the server's max size or the 5-second context timeout exceeded on slow links.","solutions":["Verify the bucket exists: `mc ls myminio` or create it via `mc mb` / console.","Check minio config in config.yaml: endpoint, access-key-id, secret-key, use-ssl must match the server; test with `mc alias set`.","Confirm the access key has write policy on the bucket (readwrite).","Check network reachability from the app host: `curl http://<endpoint>/minio/health/live`.","Inspect the wrapped err text in the log line '上传文件到minio失败' for the specific S3 error code and act on it."],"exampleFix":"// before\nclient.PutObject(putCtx, global.GVA_CONFIG.Minio.BucketName, filePathres, &filecontent, file.Size, minio.PutObjectOptions{ContentType: contentType})\n// after\n// ensure bucket exists at startup\nexists, _ := client.BucketExists(ctx, global.GVA_CONFIG.Minio.BucketName)\nif !exists {\n    _ = client.MakeBucket(ctx, global.GVA_CONFIG.Minio.BucketName, minio.MakeBucketOptions{})\n}","handlingStrategy":"try-catch","validationCode":"// Go: pre-check config before calling UploadFile\nif global.GVA_CONFIG.Minio.BucketName == \"\" || global.GVA_CONFIG.Minio.Endpoint == \"\" {\n    return errors.New(\"minio upload misconfigured: empty bucket or endpoint\")\n}","typeGuard":null,"tryCatchPattern":"path, key, err := uploadClient.UploadFile(ctx, fh)\nif err != nil {\n    logger.Error(\"upload to minio failed: %v\", err)\n    c.JSON(500, gin.H{\"code\": 7, \"msg\": \"文件上传失败，请稍后重试\"})\n    return\n}","preventionTips":["Ensure the bucket exists at deploy time (mc mb or IaC) before the app accepts uploads.","Grant the access key readwrite policy on the bucket.","Monitor MinIO health endpoint and alert on downtime.","Keep file sizes within proxy/timeout limits; the upload uses a 5s context so tune timeouts for large files.","Log the wrapped underlying error to distinguish config vs network causes."],"tags":["minio","upload","s3","object-storage"],"backgroundTag":"object-storage-upload-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}