API for direct cargo's crates upload #11666

Open
opened 2025-11-02 09:44:00 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @podsvirov on GitHub (Sep 16, 2023).

Feature Description

As described in documentation, if I have *.deb package - I can upload it via API:

PUT https://gitea.example.com/api/packages/{owner}/debian/pool/{distribution}/{component}/upload

I want similar api for cargo packages (*.crate):

PUT https://gitea.example.com/api/packages/{owner}/cargo/upload

Screenshots

No response

Originally created by @podsvirov on GitHub (Sep 16, 2023). ### Feature Description As described in [documentation](https://docs.gitea.com/usage/packages/debian#publish-a-package), if I have `*.deb` package - I can upload it via `API`: ``` PUT https://gitea.example.com/api/packages/{owner}/debian/pool/{distribution}/{component}/upload ``` I want similar api for `cargo` packages (`*.crate`): ``` PUT https://gitea.example.com/api/packages/{owner}/cargo/upload ``` ### Screenshots _No response_
GiteaMirror added the topic/packagestopic/apitype/proposal labels 2025-11-02 09:44:00 -06:00
Author
Owner

@KN4CK3R commented on GitHub (Sep 17, 2023):

The endpoint is /cargo/api/v1/crates/new.

@KN4CK3R commented on GitHub (Sep 17, 2023): The endpoint is `/cargo/api/v1/crates/new`.
Author
Owner

@podsvirov commented on GitHub (Sep 17, 2023):

@KN4CK3R can you write example of usage like for debian?

curl --user your_username:your_password_or_token \
     --upload-file path/to/file.deb \
     https://gitea.example.com/api/packages/testuser/debian/pool/bionic/main/upload
@podsvirov commented on GitHub (Sep 17, 2023): @KN4CK3R can you write example of usage like for `debian`? ``` curl --user your_username:your_password_or_token \ --upload-file path/to/file.deb \ https://gitea.example.com/api/packages/testuser/debian/pool/bionic/main/upload ```
Author
Owner

@KN4CK3R commented on GitHub (Sep 17, 2023):

This endpoint intended to be called by cargo publish but you can just send a PUT request with curl if you want to do that.

@KN4CK3R commented on GitHub (Sep 17, 2023): This endpoint intended to be called by `cargo publish` but you can just send a PUT request with curl if you want to do that.
Author
Owner

@podsvirov commented on GitHub (Sep 17, 2023):

I'm trying type:

curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate \
    https://gitea.example.com{xxx}/cargo/api/v1/crates/new

with diffirent {xxx} path variants (for example: empty, /{user}, /{organization}...) but allways get:

Not found.

UPDATE: Right path in https://gitea.example.com/{owner}/_cargo-index/config.json.

UPDATE2: Now I'm learning Web API from The Cargo Book.

@podsvirov commented on GitHub (Sep 17, 2023): I'm trying type: ``` curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate \ https://gitea.example.com{xxx}/cargo/api/v1/crates/new ``` with diffirent {xxx} path variants (for example: empty, /{user}, /{organization}...) but allways get: ``` Not found. ``` *UPDATE*: Right path in `https://gitea.example.com/{owner}/_cargo-index/config.json`. *UPDATE2*: Now I'm learning [Web API](https://doc.rust-lang.org/cargo/reference/registry-web-api.html) from `The Cargo Book`.
Author
Owner

@KN4CK3R commented on GitHub (Sep 18, 2023):

curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate https://gitea.example.com/api/packages/{user}/cargo/api/v1/crates/new

@KN4CK3R commented on GitHub (Sep 18, 2023): `curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate https://gitea.example.com/api/packages/{user}/cargo/api/v1/crates/new`
Author
Owner

@podsvirov commented on GitHub (Sep 28, 2023):

curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate https://gitea.example.com/api/packages/{user}/cargo/api/v1/crates/new

Unfortunately It's not work, because:

The body of the data sent by Cargo is:

  • 32-bit unsigned little-endian integer of the length of JSON data.
  • Metadata of the package as a JSON object.
  • 32-bit unsigned little-endian integer of the length of the .crate file.
  • The .crate file.
@podsvirov commented on GitHub (Sep 28, 2023): > `curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate https://gitea.example.com/api/packages/{user}/cargo/api/v1/crates/new` Unfortunately It's not work, [because](https://doc.rust-lang.org/cargo/reference/registry-web-api.html#publish): >The body of the data sent by Cargo is: > - 32-bit unsigned little-endian integer of the length of JSON data. > - Metadata of the package as a JSON object. > - 32-bit unsigned little-endian integer of the length of the .crate file. > - The .crate file.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#11666