Skip to content

fix(cli): send the content type of raw files in oa upload - #460

Merged
M0Rf30 merged 1 commit into
openartifact:mainfrom
orcamedia:fix/oa-upload-raw-content-type
Nov 10, 2026
Merged

M0Rf30 merged 1 commit into
openartifact:mainfrom
orcamedia:fix/oa-upload-raw-content-type

Conversation

@orcamedia

Copy link
Copy Markdown
Contributor

oa upload stores every file in a raw repository as application/octet-stream.

importTarget.putFile sends sourceAsset.ContentType, or application/octet-stream when it is empty. oa import fills it from Nexus or Artifactory, but oa upload never sets it, and the raw handler stores the request's Content-Type (it only sniffs when there is none). So a PDF, an image or a Markdown file uploaded with oa upload downloads instead of displaying, because raw only displays images, PDF and text/plain inline.

Reproduced against a 0.21.0 server, same files:

file oa from main this PR
brief.pdf application/octet-stream application/pdf
notes.md application/octet-stream text/plain; charset=utf-8

Fix

For raw uploads only, uploadCIFile sets the asset's content type (internal/oacli/upload_content_type.go):

  • By extension for the types Go's mime package knows without the system tables (.css, .html, .js, .json, .pdf, .svg, .xml, .wasm, PNG/JPEG/GIF/WebP/AVIF). It's a fixed table rather than mime.TypeByExtension, so every machine sends the same type: system tables differ, and some map .md to text/markdown, which raw would serve as a download.
  • Otherwise sniffed from the first 512 bytes with http.DetectContentType, exactly what the server does for an upload without a Content-Type. The file is rewound, and the digest check still verifies what was stored.

Maven, Ivy and sbt uploads are unchanged.

Tests

  • TestContractCIUploadRawContentType: a .PDF (case-insensitive extension), a .css that sniffing would call text/plain, a .md sniffed as text, and an unknown binary; each asserts the Content-Type of the PUT and that the whole file was sent. All but the binary fail without the fix (they arrive as application/octet-stream).
  • The contract harness gains an optional header check on recorded calls for this.

Docs: docs/integrations/ci.md (supported formats) and an entry in the "Unreleased" upgrade notes. Files uploaded before keep their stored type.

Checked locally: make check, go test -race ./internal/oacli/, the slim build, the unit suite with -race, and the before/after upload above against a local server.

🤖 Generated with Claude Code

oa upload sent every file to a raw repository as application/octet-stream:
putFile falls back to it when the asset has no ContentType, and oa upload
(unlike oa import, which takes the source system's type) never set one. A
raw repository stores and serves that type, so a PDF, an image or a text
file uploaded with oa upload downloaded instead of displaying.

For raw uploads, take the type from the extension for the types Go's mime
package knows without the system tables (fixed, so every machine sends the
same type; some system tables map .md to text/markdown, which raw serves as
a download), else detect it from the first 512 bytes like the server does
for an upload without one.

The contract test can now assert request headers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@M0Rf30
M0Rf30 merged commit 13cb73f into openartifact:main Nov 10, 2026
23 checks passed
@M0Rf30

M0Rf30 commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks @orcamedia, merged!

M0Rf30 pushed a commit that referenced this pull request Nov 11, 2026
GET /api/v1/search and the MCP search_artifacts tool keep the artifacts
carrying a property: prop:KEY=VALUE in q, or the repeatable prop parameter
for values with spaces. Exact match, all filters must hold, at most 10;
q may be left out, as with flagged=true. A filter matches the id the web UI
and oa store properties under (a package_files row of the same repository);
docker images are left out for now. With prop no repositories are returned.
Malformed filters are 400 invalid_filter (a tool error on MCP).

Each filter is applied in the shape that fits how many properties match,
decided by a bounded count: up to 1000 by an id array pushed into the
search source, so package_files is probed by primary key (Postgres cannot
push a join into the UNION ALL); more as a correlated EXISTS, which the
capped search can stop early. Migration 029 adds
idx_artifact_properties_key_value (key, value) INCLUDE (artifact_ref_id),
built concurrently.

The upgrade notes get a new "Unreleased" section with this and the oa
upload content-type change of #460, which was filed under 0.23.0 although
it merged after that release.

Closes #459

Co-authored-by: Areef <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@orcamedia
orcamedia deleted the fix/oa-upload-raw-content-type branch November 11, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants