Skip to main content
Last updated: 6 Oct 2023

Manage assets

Removing an asset

If you need to remove an asset manually from, follow these steps:

  1. Identify whether the asset was published using Whitehall or another application.

An example Whitehall asset URL is

An example non-Whitehall asset URL is

Decide if the asset can be marked as deleted or whether all traces need to be removed (e.g. if it contains secret information). If all traces need to be removed, append ,true in the square brackets when running the rake tasks below.

To mark the file as deleted, run one of the following Rake tasks:

Whitehall Assets, where LEGACY_URL_PATH is the document slug, i.e. /government/uploads/system/uploads/attachment_data/file/12345/filename.pdf for the example above. The square brackets are part of the command, so don’t remove them: sh k exec deploy/asset-manager -- rake assets:whitehall_delete[LEGACY_URL_PATH]

Other Assets, where ASSET_ID is the asset ID, i.e. abcd1234efgh from the example above (keep the square brackets): sh k exec deploy/asset-manager -- rake assets:delete[ASSET_ID]

  1. Add a query string to the URL (e.g. ?cache-bust=12345) to bypass the cache and check that the asset responds with a 404 not found.

  2. Wait 20 minutes for the cache to clear, or purge it yourself.

  3. Verify that the asset is not there without using query string.

  4. Request removal of the asset using the Google Search Console.

  5. Remove the asset from the Google Cloud Platform (GCP) mirror:

    • Log into the GCP console.
    • Go to the GOVUK Production project under the DIGITAL.CABINET-OFFICE.GOV.UK organisation.
    • Select Cloud Storage -> Browser, go to the govuk-production-mirror bucket.
    • Navigate to the file, then delete it.
  6. Remove the asset from the Amazon Web Services (AWS) mirror:

gds aws govuk-production-poweruser aws s3 rm s3://govuk-production-mirror/<slug>

Redirecting an asset

Sometimes it might be necessary to manually redirect an asset, for example if an associated document wasn’t unpublished correctly. There are some Rake tasks available for this:

k exec deploy/asset-manager -- rake assets:redirect[ASSET_ID,REDIRECT_URL]
k exec deploy/asset-manager -- rake assets:whitehall_redirect[LEGACY_URL_PATH,REDIRECT_URL]

Uploading an asset

Some publishing apps such as Mainstream Publisher do not provide the facility for editors to upload assets such as images and PDFs. In these rare cases, we can upload assets to asset-manager manually and give the URL to content editors to embed.

Production assets are replicated to staging and integration nightly, so it is best to simply perform the upload directly in production. First, upload the asset to a backend machine:

$ gds govuk connect scp-push -e production aws/backend:1 my_file.jpg /tmp

Then SSH to the same machine and run the upload command:

$ gds govuk connect ssh -e production aws/backend:1
$ cd /var/apps/asset-manager
$ sudo -u deploy govuk_setenv asset-manager bin/create_asset /tmp/my_file.jpg

Note the basepath the script outputs. This should be appended to the asset host, for example:

Replacing an asset

If you need to replace the file of an existing attachment without changing the URL, follow these steps:

  1. Copy the new file from your computer to a backend server:

    $ gds govuk connect scp-push -e <environment> aws/backend:1 filename.ext /tmp
  2. Get an app console on that same server:

    $ gds govuk connect ssh -e <environment> aws/backend:1
    $ govuk_app_console asset-manager
  3. Find the asset:

    asset = Asset.find("asset-id-from-url") # e.g. `57a9c52b40f0b608a700000a`
    # or for a Whitehall asset:
    asset = WhitehallAsset.find_by(legacy_url_path: '/government/uploads/system/uploads/attachment_data/file/id/path.ext')
  4. Check the asset is what you think it is.

  5. Replace the file (change 123 to the new attachment size in bytes):

    asset.update(size: 123)
    asset.file ="/tmp/filename.ext").open!
  6. For a Whitehall attachment, update the file size in Whitehall, where 123 is the new attachment size in bytes:

   $ gds govuk connect app-console -e <environment> whitehall_backend/whitehall
   attachment = Attachment.find_by(attachment_data_id: asset-id-from-url) # e.g. 123456
   attachment.attachment_data.update(file_size: 123, number_of_pages: 28)