Skip to content

Commit 63fa05b

Browse files
committed
docs(api-docs): add iterator example to artifact download
Document the usage of the action="iterator" option when downloading artifacts
1 parent 8cc4cfc commit 63fa05b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/gl_objects/pipelines_and_jobs.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ You can also directly stream the output into a file, and unzip it afterwards::
274274
subprocess.run(["unzip", "-bo", zipfn])
275275
os.unlink(zipfn)
276276

277+
It is also possible to use the underlying iterator directly::
278+
279+
artifact_bytes_iterator = build_or_job.artifacts(streamed=True, action='iterator')
280+
281+
This can be used with FastAPI/Starlette StreamingResponse to forward a download from gitlab without having to download
282+
the entire file server side first::
283+
284+
@app.get("/download_artifact")
285+
def download_artifact():
286+
artifact_bytes_iterator = build_or_job.artifacts(streamed=True, action='iterator')
287+
return StreamingResponse(artifact_bytes_iterator, media_type="application/zip")
288+
277289
Delete all artifacts of a project that can be deleted::
278290

279291
project.artifacts.delete()

0 commit comments

Comments
 (0)