flipped-aurora/gin-vue-admin · error

上传文件到minio失败, err:

Error message

上传文件到minio失败, err:

What it means

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.

Source

Thrown at server/utils/upload/minio_oss.go:87

	} else {
		filePathres = global.GVA_CONFIG.Minio.BasePath + "/" + time.Now().Format("2006-01-02") + "/" + filename
	}

	// 根据文件扩展名检测 MIME 类型
	contentType := mime.TypeByExtension(ext)
	if contentType == "" {
		contentType = "application/octet-stream"
	}

	// 设置超时10分钟
	putCtx, cancel := context.WithTimeout(ctx, time.Minute*10)
	defer cancel()

	// Upload the file with PutObject   大文件自动切换为分片上传
	info, err := client.PutObject(putCtx, global.GVA_CONFIG.Minio.BucketName, filePathres, &filecontent, file.Size, minio.PutObjectOptions{ContentType: contentType})
	if err != nil {
		logger.WithCtx(ctx).Mod("upload").Err(err).Error("上传文件到minio失败")
		return "", "", errors.New("上传文件到minio失败, err:" + err.Error())
	}
	return global.GVA_CONFIG.Minio.BucketUrl + "/" + info.Key, filePathres, nil
}

func (m *Minio) DeleteFile(ctx context.Context, key string) error {
	client, err := newMinioClient()
	if err != nil {
		logger.WithCtx(ctx).Mod("upload").Err(err).Error("minio client 初始化失败")
		return errors.New("minio client 初始化失败, err:" + err.Error())
	}

	delCtx, cancel := context.WithTimeout(ctx, time.Second*5)
	defer cancel()

	// Delete the object from MinIO
	err = client.RemoveObject(delCtx, global.GVA_CONFIG.Minio.BucketName, key, minio.RemoveObjectOptions{})
	return err
}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Verify the bucket exists: `mc ls myminio` or create it via `mc mb` / console.
  2. Check minio config in config.yaml: endpoint, access-key-id, secret-key, use-ssl must match the server; test with `mc alias set`.
  3. Confirm the access key has write policy on the bucket (readwrite).
  4. Check network reachability from the app host: `curl http://<endpoint>/minio/health/live`.
  5. Inspect the wrapped err text in the log line '上传文件到minio失败' for the specific S3 error code and act on it.

Example fix

// before
client.PutObject(putCtx, global.GVA_CONFIG.Minio.BucketName, filePathres, &filecontent, file.Size, minio.PutObjectOptions{ContentType: contentType})
// after
// ensure bucket exists at startup
exists, _ := client.BucketExists(ctx, global.GVA_CONFIG.Minio.BucketName)
if !exists {
    _ = client.MakeBucket(ctx, global.GVA_CONFIG.Minio.BucketName, minio.MakeBucketOptions{})
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: pre-check config before calling UploadFile
if global.GVA_CONFIG.Minio.BucketName == "" || global.GVA_CONFIG.Minio.Endpoint == "" {
    return errors.New("minio upload misconfigured: empty bucket or endpoint")
}

Try / catch

path, key, err := uploadClient.UploadFile(ctx, fh)
if err != nil {
    logger.Error("upload to minio failed: %v", err)
    c.JSON(500, gin.H{"code": 7, "msg": "文件上传失败,请稍后重试"})
    return
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/c5432bdf7eeda9a8. Report an issue: GitHub.