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

304
Views
Elemento de almacenamiento de Firebase no encontrado usando getFiles o deleteFiles

Estoy usando una función de Firebase para eliminar archivos cuando se elimina un elemento de Firestore, cada entrada de FireStore tiene 2 archivos: image.jpg e image_thumb.jpg

Estoy tratando de eliminar ambos archivos usando el prefijo del depósito, sin embargo, los archivos no se encuentran, he intentado usar el método getFiles para ver los elementos antes de eliminarlos, pero esto tampoco arroja resultados.

 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}`})

Si elimino la referencia ${photoId} y solo busco la carpeta, obtengo un resultado correcto

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

Esto devuelve los siguientes datos

 [ > [ > 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

Si elimino la referencia ${photoId} y solo busco la carpeta, obtengo un resultado correcto

Este es realmente el comportamiento previsto, como se muestra en la documentación de Cloud Storage (consulte la pestaña "Node.js"): no debe incluir, en el valor del prefix , la última parte del nombre del archivo (es decir, la parte después de la última / , o, si usamos el paradigma del árbol de directorios, el propio nombre del archivo, sin los directorios principales).

El ejemplo de código contiene estas explicaciones:

 /** * This can be used to list all blobs in a "folder", eg "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!