Khi tôi xóa bài đăng trong cơ sở dữ liệu Firebase của mình, tôi muốn có chức năng đám mây để xóa hình thu nhỏ của bài đăng trong bộ nhớ firebase tương ứng. Vấn đề của tôi là khi tôi đang cố xóa hình thu nhỏ, tôi không nghĩ rằng tôi đang định vị tệp hình ảnh chính xác.Làm thế nào để xóa một tập tin bằng cách sử dụng chức năng đám mây?
Dưới đây là những gì tôi đã cố gắng:
const functions = require('firebase-functions')
const admin = require('firebase-admin')
const gcs = require('@google-cloud/storage')()
exports.deletePost = functions.database.ref('Posts/{pushId}').onWrite(event => {
const original = event.data.val()
const previous = event.data.previous.val()
const pushId = event.params.pushId
if (original === null)
return
const filePath = 'Posts/' + pushId + 'thumbnail.jpg'
const bucket = gcs.bucket('postsapp-12312')
const file = bucket.file(filePath)
const pr = file.delete()
return pr
});
Đây là những gì tôi nhận được trong nhật ký
ApiError: Not Found at Object.parseHttpRespBody (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:192:30) at Object.handleResp (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:132:18) at /user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:465:12 at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/storage/node_modules/retry-request/index.js:120:7) at Request.self.callback (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:188:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:1171:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7)
Cái mà bạn sử dụng để xóa là GCS không phải là hàm firebase. Bạn đang sử dụng các chức năng để nghe thay đổi db và xóa qua GCS – vzhen
@vzhen yes^đó là cách duy nhất để làm điều đó vào thời điểm đó, có bất kỳ thay đổi nào bây giờ không? bạn có thể đưa ra câu trả lời tốt hơn không? – Faisal
Tôi cũng đang tìm kiếm. Tôi đang sử dụng bộ nhớ Firebase chứ không phải GCS. Có vẻ như kho lưu trữ sdk của firebase không hỗ trợ xóa phía máy chủ. – vzhen