Is there any way to limit the amount of the number of pictures inserted in to firestore bucket? [duplicate] - google-cloud-firestore

This question already has answers here:
How to limit a number of firebase storage of images? [duplicate]
(2 answers)
Limit number of files in a firebase storage path
(1 answer)
How can I set limit on the amount of storage that each user can upload to Firebase Storage?
(2 answers)
Closed 16 days ago.
I am working on a feature in my app that allow the user to add up to 20 images to storage … but not more that that I will implement a front end limit but I want to do this in security rules as well .. images go under the user uid, the issue here is how to get control over the images file in bucket so it can have only 20 pics ? similar to an array.size or map.size ?
// storageRef
const storageRef = ref(storage,`images/${currentUser?.uid}/{imgId}`);
// Rules
match /images/{userId}/{img} {
// Add to Storage
allow write:
if isAuthed() &&
request.resource.size < 524288 &&//Size
request.resource.contentType.matches('image/.*'); // Type
}
}

Related

How to get a child name in Firebase Realtime Database? [duplicate]

This question already has answers here:
Firebase queryOrderedByChild() method not giving sorted data
(2 answers)
Retrieving Data using Firebase Swift
(1 answer)
Get the data from all children in firebase using swift
(2 answers)
Swift Firebase -How to get all the k/v when using queryOrdered(byChild: ).queryEqual(toValue: )
(1 answer)
Closed 3 months ago.
I have a Firebase Realtime Database and want to get the name of a child in the last part of a branch.
The database structure looks like this:
How do I get the "FD4936E20732A42E" and possible other child names of "friends"?
"FD4936E20732A42E" and other possible childs of "friends" are not string values I know before runtime.
I know how I would for example access the value for a specific part of the database. But in this case using snapshot.value and snapshot.key did not work.
I really appreciate any kind of help. I am really desperate.
Update - I tried this but the output is a FIRDataSnapshot and I need a String. A downcast is not working:
let ref = Database.database().reference().child("visitors").child("107C081B-4117-4E2F-8E39-BF896D366B30")
ref.child("friends").observeSingleEvent(of: .value) { snapshot in
for child in snapshot.children {
print(child)
}
}
The output I get:
Snap (FD4936E20732A42E) 1

keep the size of array in a document less than or equal to 9

I am using Firestore and have users documents with images array. I am able to add / delete images from the images array without any problem. Both add and delete operations to the array are considered update to the user document. I would like to have an update security rule such that I can't have more than 9 images.
I am using the following rule:
allow update: if resource.data.images.size() < 9
As soon as I have nine images in the array, I am no longer able to delete an image. So the rule is conflicting for add and remove. What is the best way to handle this. I appreciate any help.
Thanks
resource.data contains the fields in the document that currently exist. request.resource.data contains the fields that are about to be written by the client app. You will want to use the latter to check the incoming fields rather than the existing fields.
allow update: if request.resource.data.images.size() < 9

Persist to google assistant data to a Database ( The data fetched from google assistant dialog )?

I am able to get data using google actions but need your help in store this data into the database so that the user does not have to provide information every time he interacts with my action . Any help on this please
I am developing a stock app , collects names and quantity of various company names the user has invested in. , post that user should be able to ask various questions about his portfolio on a day to day basis ?
The easiest way to persist user data is to use the built-in user storage feature. This will allow you to save data for a user across conversations.
Here's an example of how it works:
function simpleResponse(conv) {
conv.user.storage.count = 1;
conv.ask(new SimpleResponse({
speech: 'Howdy! I can tell you fun facts about ' +
'almost any number, like 42. What do you have in mind?',
text: 'Howdy! I can tell you fun facts about almost any ' +
'number. What do you have in mind?',
}));
}

How to make transactions on multiple data tables in Firebase?

I've an application, which uses Firebase. I have a new post adding. And when I make it, I do a number of operations in database, like:
Add new post info to Posts node
Add Id of the new post to Users node
Upload media to storage
etc.
So, for example, user can close application on step 2. How can I reset data on start of adding new post?
If I've understood correctly, Firebase transactions work on only one data table.
Main question is: how to make transactions on multiple data tables and storage in Firebase?
I believe you're looking for something like this: https://firebase.google.com/docs/database/web/read-and-write#update_specific_fields. It allows you to run multiple updates all at once to wherever you need. Here is a snapshot of the code:
var updates = {};
updates['/posts/' + newPostKey] = ...;
updates['/user-posts/' + uid + '/' + newPostKey] = ...;
return firebase.database().ref().update(updates);

Separate search in different tables with sphinx [duplicate]

This question already has answers here:
Searching a particular index using Sphinx, from multiple indexes, through PHP script
(2 answers)
Closed 8 years ago.
In my case content are saving in table
content_en
Search with sphinx works good.
I would to add another table content_es and make search in this table.
And if user will be search on en version site - i would use content_en table, if on spain version - content_es table.
I can search in 2 tables and on PHP side make filter, but I think it's not correct.
How it's make correct ? (like $sphinx->SetOption() or $sphinx->SetIndex()) ?
$res = $cl->Query($query,"content_es");