Reputation: 85
After uploading a file in Firebase storage I want to call a firebase cloud function from my web app which will validate the file data I sent to it, and then store it in the real-time database.
I am calling the function using the following code:
var fileRef = 'Files/' + user.uid + '/' + fileId + '/' + file.name;
var storage = firebase.storage().ref(fileRef);
//Upload the file
//..................
// After uploading the file
storage.getMetadata().then(function(metadata) {
var date = metadata.timeCreated.toString();
var storage = firebase.storage().ref('Files/' + user.uid + '/' + fileId + '/' + file.name);
storage.getDownloadURL().then(function(url){
var saveFileData = functions.httpsCallable('saveFileData');
saveFileData({
fileId: fileId,
fileRef: fileRef,
fileData: {
Uploader: user.uid,
Title: title,
FileName: file.name,
Size: fileSize,
DownloadURL: url,
UploadDate: date,
}
}).then(function(){
// Do something
});
});
});
I want to validate values of FileName, Size, DownloadURL and UploadDate in the cloud function based on the following conditions:
What will be an appropriate way to do this from Firebase cloud function?
Upvotes: 0
Views: 1120
Reputation: 596
You can use storage triggers, Deploy in Firebase Cloud Functions,
In the object you will get all the metadata for the uploaded file as like here
exports.generateMetaForUpload = functions.storage
.object()
.onFinalize(object => {
console.log(object);
//do whatever you need to verify
});
Upvotes: 3