Google Cloud Storage: download a file with a different name

example (first option Brandon Yarbrough) with javascript library:

const storage = new Storage()
const fileBucket = storage.bucket('myBucket')
const file = fileBucket.file('MyOriginalFile.txt')
const newName = "NewName.txt"
await file.save(content, {
    metadata: {
      contentDisposition: `inline; filename="${newName}"`
    }
  })

The response-content-disposition parameter can only be used by authorized requests. Anonymous links don't work with it. You have a few options:

  1. The content-disposition of a particular object is part of its metadata and can be permanently set. If you always want a specific file to be downloaded with a specific name, you can just permanently set the content-disposition metadata for the object.

  2. You can also generate signed URLs that include the response-content-disposition query parameter. Then the users will be making authorized requests to download the resource.