4

I am uploading images for user profiles to Firebase with a path such as profiles/${userId}/image.jpg.

After every upload, I trigger a cloud function that gets the signed url with GCS like in this example:

const SIGNED_BUCKET_URL_CONFIG = {
    action: 'read',
    expires: '03-01-2501'
};
const bucket = gcs.bucket(BUCKET_NAME);
const profileImageRef = bucket.file(`profiles/${userId}/image.jpg`);
const url = profileImageRef.getSignedUrl(SIGNED_BUCKET_URL_CONFIG),

Now my problem is that the returned signed URL is always the same after every upload/overwrite of the image and the mobile app does not know the cache for this image must be refreshed.

Is it maybe possible to generate a signed url with a version param, e.g. '....?v=123' ?

JL-HaiNan
  • 1,004
  • 9
  • 20
user2458046
  • 405
  • 1
  • 4
  • 14
  • You can use the generation: https://cloud.google.com/storage/docs/xml-api/reference-headers#generation to generate the signed url with versions. – JL-HaiNan Jan 19 '18 at 21:07

1 Answers1

1

A simple way to achieve this is to provide your SIGNED_BUCKET_URL_CONFIG dynamic something like the following:

const exp = Date.now() + 30 * 365 * 24 * 60 * 60 * 1000; // 30 years from now

const SIGNED_BUCKET_URL_CONFIG = {
    action: 'read',
    expires: exp
};

But the above technique may fail if multiple uploads are made at exactly the same millisecond. Therefore only choose this method if this is acceptable for your project.

siva636
  • 16,109
  • 23
  • 97
  • 135