Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

296
Views
Firebase storage item not found using getFiles or deleteFiles

I'm using a Firebase function to delete files when a firestore item is deleted, each firestore entry has 2 files: image.jpg and image_thumb.jpg

I'm trying to remove both files using the bucket prefix, however the files are not found, I've tried using the getFiles method to see the items before deleting them, but this as well returns no results.

const bucket = admin.storage().bucket()

const not_working = await bucket.getFiles({prefix: `photos/${userId}/${photoId}`})
const not_working = await bucket.deleteFiles({prefix: `photos/${userId}/${photoId}`})

If I remove the ${photoId} reference and only look for the folder, I get a correct result

const bucket = admin.storage().bucket()
const working = await bucket.getFiles({prefix: `photos/${userId}/`})

This returns the following data

[
>    [
>      File {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        metadata: [Object],
>        baseUrl: '/o',
>        parent: [Bucket],
>        id: 'photos%2FkLxGzah8zc7Vbrl0c3iLic8tkqH2%2Fcad2ce98-dfa7-4611-9a88-913328ab4590.png',
>        createMethod: undefined,
>        methods: [Object],
>        interceptors: [],
>        pollIntervalMs: undefined,
>        create: undefined,
>        bucket: [Bucket],
>        storage: [Storage],
>        kmsKeyName: undefined,
>        userProject: undefined,
>        name: 'photos/kLxGzah8zc7Vbrl0c3iLic8tkqH2/cad2ce98-dfa7-4611-9a88-913328ab4590.png',
>        acl: [Acl],
>        instanceRetryValue: true,
>        instancePreconditionOpts: undefined,
>        [Symbol(kCapture)]: false
>      },
>      File {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        metadata: [Object],
>        baseUrl: '/o',
>        parent: [Bucket],
>        id: 'photos%2FkLxGzah8zc7Vbrl0c3iLic8tkqH2%2Fcad2ce98-dfa7-4611-9a88-913328ab4590_thumb.png',
>        createMethod: undefined,
>        methods: [Object],
>        interceptors: [],
>        pollIntervalMs: undefined,
>        create: undefined,
>        bucket: [Bucket],
>        storage: [Storage],
>        kmsKeyName: undefined,
>        userProject: undefined,
>        name: 'photos/kLxGzah8zc7Vbrl0c3iLic8tkqH2/cad2ce98-dfa7-4611-9a88-913328ab4590_thumb.png',
>        acl: [Acl],
>        instanceRetryValue: true,
>        instancePreconditionOpts: undefined,
>        [Symbol(kCapture)]: false
>      }
>    ]
>  ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I remove the ${photoId} reference and only look for the folder, I get a correct result

This is actually the intended behaviour, as shown in the Cloud Storage documentation (look at the "Node.js" tab): you should not include, in the prefix value, the last part of the file name (i.e. the part after the last /, or, if we use the directories tree paradigm, the file name itself, without the parent directories).

The code example contains these explanations:

 /**
   * This can be used to list all blobs in a "folder", e.g. "public/".
   *
   * The delimiter argument can be used to restrict the results to only the
   * "files" in the given "folder". Without the delimiter, the entire tree under
   * the prefix is returned. For example, given these blobs:
   *
   *   /a/1.txt
   *   /a/b/2.txt
   *
   * If you just specify prefix = 'a/', you'll get back:
   *
   *   /a/1.txt
   *   /a/b/2.txt
   *
   * However, if you specify prefix='a/' and delimiter='/', you'll get back:
   *
   *   /a/1.txt
   */
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!