firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.61k stars 362 forks source link

SDK doesn't update filename in Content-Disposition metadata on File Rename #2055

Open abhis3 opened 1 year ago

abhis3 commented 1 year ago

Environment: NextJS 12.3.0 + React 18.2.0 Web Application (arbritrary for the sake of this issue) Emulator Version: 11.5.0

Describe the problem

Steps to reproduce:

+++

Also occurs via gcloud storage mv gs://BUCKET_NAME/OLD_OBJECT_NAME gs://BUCKET_NAME/NEW_OBJECT_NAME"

or renaming the file via the GCP console ===> Cloud Storage ===> Buckets

What Happened?

The culprit is that the Content-Disposition filename field is not updated when calling rename. You can see in the screenshot here (https://imgur.com/a/tyouzeS) that the filename is the old name of tree.jpg. Updating this value manually yields a downloaded file that has the correct name.

This issue was submitted on behalf of a Firebase Storage user

google-oss-bot commented 1 year ago

I found a few problems with this issue:

abhis3 commented 1 year ago

I talked it over with the team, we might take this up as part of a larger body of work to support more GCS operations on the Firebase Storage side. For now leaving this issue open to track how many users are running into this issue so it can be prioritized accordingly.

If we were to do this on the SDK side this would constitute a breaking change and we would likely need a new API which is not as ideal.

abhis3 commented 1 year ago

As far as immediate resolutions, Content-Disposition is a settable field (https://cloud.google.com/storage/docs/gsutil/addlhelp/WorkingWithObjectMetadata#settable-fields;-field-values) so one might have luck in updating the value themselves while the team works on a fix.

lahirumaramba commented 1 year ago

Hey @abhis3 , storage support in firebase-admin is provided through @google-cloud/storage. I think this issue would be better addressed in the https://github.com/googleapis/nodejs-storage repo.

Ronso007 commented 10 months ago

For anyone coming across this issue I will add my solution to this problem (thanks to @abhis3 for the idea)

let metadata = {
        // Here predefined key/value
        contentDisposition: "inline; filename=yourfilename.txt",

        metadata: {
          // Not here! custom key/value
        },
      };

to see the full predefined metadata properties: https://firebase.google.com/docs/storage/web/file-metadata