flipped-aurora/gin-vue-admin · error

function os.Create() failed, err:

Error message

function os.Create() failed, err:

What it means

This error is returned by Local.UploadFile when os.Create() fails to create the destination file under the configured local store path (global.GVA_CONFIG.Local.StorePath). os.Create fails when the path is unwritable, a parent directory component is missing (though MkdirAll runs first), or the target exists as a directory. The underlying OS error is appended to the message.

Source

Thrown at server/utils/upload/local.go:62

		logger.WithCtx(ctx).Mod("upload").Err(mkdirErr).Error("function os.MkdirAll() failed")
		return "", "", errors.New("function os.MkdirAll() failed, err:" + mkdirErr.Error())
	}
	// 拼接路径和文件名
	p := global.GVA_CONFIG.Local.StorePath + "/" + filename
	filepath := global.GVA_CONFIG.Local.Path + "/" + filename

	f, openError := file.Open() // 读取文件
	if openError != nil {
		logger.WithCtx(ctx).Mod("upload").Err(openError).Error("function file.Open() failed")
		return "", "", errors.New("function file.Open() failed, err:" + openError.Error())
	}
	defer f.Close() // 创建文件 defer 关闭

	out, createErr := os.Create(p)
	if createErr != nil {
		logger.WithCtx(ctx).Mod("upload").Err(createErr).Error("function os.Create() failed")

		return "", "", errors.New("function os.Create() failed, err:" + createErr.Error())
	}
	defer out.Close() // 创建文件 defer 关闭

	_, copyErr := io.Copy(out, f) // 传输(拷贝)文件
	if copyErr != nil {
		logger.WithCtx(ctx).Mod("upload").Err(copyErr).Error("function io.Copy() failed")
		return "", "", errors.New("function io.Copy() failed, err:" + copyErr.Error())
	}
	return filepath, filename, nil
}

//@author: [piexlmax](https://github.com/piexlmax)
//@author: [ccfish86](https://github.com/ccfish86)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@object: *Local
//@function: DeleteFile
//@description: 删除文件
//@param: key string

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check the appended OS error (e.g. permission denied vs no such file) and fix filesystem permissions: chown/chmod the StorePath directory so the server process can write.
  2. Verify local.store-path in config.yaml points to an existing writable absolute path and that os.MkdirAll on it succeeds.
  3. Check disk space (df -h) and quota; free space if ENOSPC.
  4. If running in Docker/K8s, confirm the volume is mounted read-write and the container user matches the volume owner.

Example fix

// before (config.yaml)
local:
  store-path: /data/uploads   # directory owned by root, process runs as app user
// after
# shell
sudo chown -R appuser:appuser /data/uploads && chmod 755 /data/uploads
Defensive patterns

Strategy: validation

Validate before calling

func ensureStoreWritable(storePath string) error {
    if err := os.MkdirAll(storePath, 0o755); err != nil {
        return fmt.Errorf("store dir unavailable: %w", err)
    }
    probe := filepath.Join(storePath, ".write-probe")
    if err := os.WriteFile(probe, []byte("ok"), 0o644); err != nil {
        return fmt.Errorf("store dir not writable: %w", err)
    }
    _ = os.Remove(probe)
    return nil
}
// call at startup: ensureStoreWritable(global.GVA_CONFIG.Local.StorePath)

Try / catch

filePath, filename, err := local.UploadFile(ctx, fileHeader)
if err != nil {
    if strings.HasPrefix(err.Error(), "function os.Create() failed") {
        // surface a 500 with admin hint: check store-path permissions/disk
    }
    return err
}

Prevention

When it happens

Trigger: Calling UploadFile on a Local upload adapter when the OS cannot create StorePath/<md5>_<timestamp><ext>: read-only filesystem or volume, insufficient file permissions for the process user, StorePath points at an existing directory with the generated filename, or disk full (ENOSPC).

Common situations: Docker containers running as non-root with the uploads volume owned by root; store path configured to a Windows drive letter that doesn't exist; disk quota exhaustion; deploying with a relative StorePath that resolves against an unexpected working directory.

Related errors


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