Download single artifact by jobID

Trying curl request to download single artifact file from artifact archive using gitlab api but throws an error “curl: (18) transfer closed with 2 bytes remaining to read”
Any help would be appreciated?

Thanks for taking the time to be thorough in your request, it really helps! :blush:

Please share the full command line leading to this error.

Quick guess: When the transfer was closed intermittently, check your network for disconnects. Maybe the artifact took a long time to download because of slow download speeds, too, resulting in the server to close the connection.

So file is very small under 10KB and connection was also fine. I use below curl command
curl --location --output artifacts.zip --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects/<id>/jobs/<jobID>/artifacts/<artifactpath>

What would be artifactpath here?

Not sure about this question, but from the docs Job Artifacts API | GitLab

Path to a file inside the artifacts archive.

Suggest showing the CI/CD configuration that generates the artifact, and the files that are expected in the artifacts archive. That can help build the URL path.

I get this same behaviour using CE v16.7.2 - it’s something to do with HAProxy combined with GitLab behaviour when the file is not found in the archive.

When running the curl directly against GitLab WITHOUT HAProxy and the verbose flag, the output includes “HTTP/1.1 404 Not Found”, but the stream is not closed cleanly. So this does appear to be a defect with GitLab not handling the file not found correctly.

< HTTP/2 404
< server: nginx
< date: Fri, 12 Jan 2024 20:22:45 GMT
< content-type: text/plain; charset=utf-8
< content-length: 2
< cache-control: max-age=0, private, must-revalidate
< etag: W/"12ae32cb1ec02d01eda3581b127c1fee"
< vary: Origin
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-gitlab-meta: {"correlation_id":"01HKZNEQQGXX74FF5BKD7XA8J3","version":"1"}
< x-request-id: 01HKZNEQQGXX74FF5BKD7XA8J3
< x-runtime: 0.090057
<
{ [5 bytes data]
* HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)
* stopped the pause stream!
  0     2    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host [REDACTED] left intact
curl: (92) HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)