HfHub.Commit.Preupload (HfHub v0.3.1)

Copy Markdown View Source

Hub preupload preflight: ask the server how each file should be uploaded (regular base64 blob vs. Git-LFS) before sending the commit.

This is the canonical equivalent of _fetch_upload_modes in huggingface_hub/_commit_api.py. The Hub consults the repo's .gitattributes (which by default tracks *.safetensors, *.bin, etc. as LFS regardless of size) and tells us, per path, which mode to use.

Sending an LFS-tracked file as a base64 "regular" blob produces:

400 Bad Request: "Your push was rejected because it contains binary
files. Please use ... to store binary files."

Always call this before building the commit ndjson so we honour the repo's declared storage policy instead of a local size threshold.

Summary

Functions

Returns {:ok, %{path_in_repo => :regular | :lfs}} for each given addition, or {:error, reason} if the Hub rejects the preflight.

Types

addition()

@type addition() :: %{
  :path_in_repo => String.t(),
  :upload_info => HfHub.LFS.UploadInfo.t(),
  optional(any()) => any()
}

repo_type()

@type repo_type() :: :model | :dataset | :space

upload_mode()

@type upload_mode() :: :regular | :lfs

Functions

fetch_upload_modes(repo_id, additions, token, opts \\ [])

@spec fetch_upload_modes(String.t(), [addition()], String.t(), keyword()) ::
  {:ok, %{required(String.t()) => upload_mode()}} | {:error, term()}

Returns {:ok, %{path_in_repo => :regular | :lfs}} for each given addition, or {:error, reason} if the Hub rejects the preflight.

Options

  • :repo_type:model (default), :dataset, or :space.
  • :revision — defaults to "main". Encoded per HF's URL contract.
  • :create_pr — when true, the request is scoped to a PR branch.