Skip to main content
Last updated: 20 Jun 2022

Manage assets

Removing an asset

If you need to remove an asset manually from assets.publishing.service.gov.uk, follow these steps:

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

An example Whitehall asset URL is https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/12345/filename.pdf.

An example non-Whitehall asset URL is https://assets.publishing.service.gov.uk/media/abcd1234efgh/filename.pdf.

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:

Other Assets, where ASSET_ID is the asset ID, i.e. abcd1234efgh from the example above (keep the square brackets):

  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 Amazon Web Services (AWS) mirror:

gds aws govuk-production-poweruser aws s3 rm s3://govuk-production-mirror/assets.publishing.service.gov.uk/<slug>

  1. 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.

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:

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:

https://assets.publishing.service.gov.uk/media/57358658ed915d58bd000000/my_file.jpg

Large attachments

Sometimes publishers ask us to help them upload very large attachments to documents in Whitehall because they see timeouts when they try to upload the document themselves.

The simplest way to do this is to upload a small file (in Whitehall) and then replace the file in Asset Manager.

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 = Pathname.new("/tmp/filename.ext").open
    asset.save!
    
  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)