Skip to content

Fix missing filename when downloading generic package in release page

Context

In Avoid copy operation in object store during Gen... (!147454 - merged), we made a change to the way the packages are uploaded to the Generic Package Repository: Instead of uploading the file to a temp location on the Object Storage, and then make a copy operation to move the file to its final location, we now upload the file to its final location directly.

This caused a bit of a side effect: the file now is uploaded and resides on the Object Storage without its file name. So when we download the file, we rely on rails to attach the correct file name to the download response so that the browser respects this name and download the file with its correct name.

This part in the codebase is responsible for attaching the name to the download response when a package is downloaded from the UI.

The generic packages can be used in the project's release feature. On the release page, the generic packages can be referenced for download. However, the download URL for those packages are different from the one used for download in the package registry:

  • Download URL in the package registry: https://gitlab.com/<group>/<project>/-/package_files/<package_file_id>/download
  • Download URL in the release page: https://gitlab.com/api/v4/projects/<project_id>/packages/generic/<package_name>/<package_version>/<package_file_name>

As we can see, the release page is trying to download the package using an API endpoint, and because of that, the download URL on the release page doesn't follow the same code path that the package registry URLs follow, and this resulted in not attaching the file name to the download response.

However, this bug doesn't occur on gitlab.com, it only occurs on the self-managed instances that use aws as an Object Storage. The part in the codebase that handles the download response is missing the params that should attach the file name to the download response.

What does this MR do and why?

  • Pass missing redirect_params to ObjectStorage::CDN::FileUrl.new in #present_carrierwave_file method.
  • Cover the fix with tests

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Enable the Object Storage in your GDK.
  2. Publish a dummy generic package to the package registry:
    curl --header "PRIVATE-TOKEN: <your_access_token>" \
      --upload-file path/to/file.txt \
      "http://gdk.test:3000/api/v4/projects/<project_id>/packages/generic/my_package/0.0.1/file.txt"
  3. After the package is published successfully, navigate to the project's releases page in the UI and create a new release.
  4. In the opened new release form, there's a section at the bottom of the page named Release assets. Under it, we need to link the release to the generic package we published in step 2.
  5. In the URL field, add the download URL of the package: http://gdk.test:3000/api/v4/projects/<project_id>/packages/generic/my_package/0.0.1/file.txt, and fill the Link title field with the name of the package file file.txt, and from the Type dropdown list, choose Package.
  6. Click on Create release button. After that, in the created release page, you should see a section named Packages with a list of the assets we linked to the release. In our release, it should be only our dummy generic package.
  7. Click on the package to download it. The package file should be downloaded correctly by its name
  8. Switch to master branch and try to download the same package again, this time the file will be downloaded but with a weird long hash as the name

Related to #465102 (closed)

Edited by Moaz Khalifa

Merge request reports

Loading