Arun Arun - 6 months ago 39
Ruby Question

GitLab archive over API creating endless zips inside zips

I am using the GitLab API to create repository archives and when I do it creates a zip file that has a zip inside, that has a zip inside, etc.

Here is the code that is making the request:

def self.get_archive(project_id, branch)
request =
BASE_URL + "/projects/#{project_id}/repository/archive?sha=#{branch}",
method: :get,
params: nil,
headers: {

response = request.response

if response.success?
file_name = "archive-#{SecureRandom.hex(5)}.zip" + "public/archives/" + file_name, "wb") do |file|

return {
success: true,
file_path: "/archives/" + file_name
return {
success: false,
response_raw: response

Any thoughts as to what's gone wrong? My thinking here was to take the binary that I get back and write it to a zip file.


So it turns out that GitLab sends back by default a tar.gz file. To receive the Zip file instead you have to explicitly specify the .zip extension to the end of the request. Like so:


The .zip at the end of "archive" was the important factor.