I got a problem with Firebase Storage, updateMetadata() function. I want to add custom Metadata, but updateMetadata overwrites all properties. I use Firebase Storage on Flutter. Here is the code:
StorageReference storageReference = _firebaseStorage.ref().child('filename');
storageReference.updateMetadata(StorageMetadata(customMetadata: {'receiver': 'ID'}));
I just want to add the receiver with the given ID, but every other property like content-type is being overwritten. Is this a common issue or is there a different way to solve this problem?
Regards, Tom
The documentation says:
You can update file metadata at any time after the file upload completes by using the updateMetadata() method. Refer to the full list for more information on what properties can be updated. Only the properties specified in the metadata are updated, all others are left unmodified.
So what you're seeing is not the expected behavior as far as I can tell. I can reproduce it, filed a bug report on the FlutterFire repo.
Until that bug is fixed, if you want to modify the metadata, you can work around the bug with these steps:
Read the existing metadata
Make the change to the values you read
Write the updated, complete metadata back
Related
i have manually added the data in cloud firestore
this how the data looks like .
Now using those fields i.e(id, location, model, equipmentCoordinates) how to create the constructor for that in flutter like this and call it. so that i can use the constructor and call it everwhere i need. It will be so helpful if you can answer this.
You can do it manually and also use this site for lengthy data models https://app.quicktype.io/
please check the image below for reference you can choose language and give data as you saved in the database,
I am using Firebase Translate Text Extension to translate few documents fields in my project. I want to add one more field that is in a documents in the nested collection:
So each document in collection "spots_test" has collection "reviews". I want to translate one field in each new review added, and I am wondering how can I set up it in Firebase Translate Text Extension, I was trying to set up something like this, but it didn't work:
Is there any way to handle nested collections?
I wasn't able to find proper documentation, however I experimented a bit. It seems to be working this way on my side (LevelOne is collection, test is sub-collection in any document of the collection):
LevelOne/{doc}/test
I don't think that it's important what is in the brackets I tested {something} as well. Working fine.
As this is Firebase Function base feature, I tried the same wildcards logic as in Firebase Function background triggers for Firestore. To be honest, as I didn't found any documentation in extension docs so I am not sure if this is intended behavior, but it works.
UPDATE:
I have continued the test. The extension is generating function visible in Functions tab of Firebase console. The trigger is visible there. The value of the trigger is gendered from extension configuration "Collection path"+{messageId}. So for example you can setup:
{collection}/{doc}/{subcollection}
In this situation translate text extension will work on every document in 2nd level collection no matter what the path is.
I'm developing an image posting app that lets users post image files to firebase's cloud storage.
Map <String, String> type information can be written to the metadata of the image file.
So when the user posts an image, as metadata
{'displayability':'false'}
Is stored.
And after the administrator checks the posted image, the metadata of the image
{'displayability':'true'}
Update to.
And in the image list list display, I checked the metadata,
"{'Displayability':'true'}" as metadata
I want to show the user only the files that hold.
However, I'm not sure what to do specifically.
When I read documents etc., it means server side processing,
so I wonder if I will use cloud functions, but
If you have any hints, please teach me.
As far as I know, there is no efficient way to "query" the images based on their metadata except for downloading them all then process it client side, which is not advisable in any case. Instead, I suggest you use a Firestore collection to keep track of which image has been approved by the admin. Each document should be something like this:
{
"ref": "path/to/image",
"displayability": true //or false, depends on whether the image has been approved
//You can add any additional info here, like upload time, uploader's name, etc...
}
Then you can make a simple query to Firestore to get a list of approved images, then download them from Cloud Storage. And when you need to get list of unapproved images, the process is basically the same. This solution doesn't require any Cloud Functions code at all.
There is a method called "updataMetadata(SettableMetadata metadata)".
just pass the updated metadata using above function.
According to the docu "[...] VueFire will automatically bind up to one nested references.". That works well, if I retrieve an object (map) from the database with a property being a ref: The ref gets ressolved automatically on the client (ref_property will not hold the path to the object (e.g. users/123) but the actual data ({username: 'john', hometown: 'autumn'}).
Question is: How do I update a ref_property (e.g. suppose a last_edit_by_ref) on the client in a way, that a.) VueFire is able to resolve this to a valid JSON for the UI and b.) make sure that it's stored as a ref in the database at the same time?
I tried to fetch the referenced object (again) from the collection as explained here ("To write a reference to a document, you pass the actual reference object"). The issue with this is however, that VueFire does not ressolve this, leading to empty values in the UI:
post.last_edit_by_ref = db.collection('users').doc('123')
Background: If I'm setting plain JSON, the property is no longer stored as a reference in the database. This is bad, since the linked object is likely to be changed (and the linking objekt would then hold copied, outdated data).
It does not related to VueFire. It is how firebase parse the Object it get in the set/update methods.
If you focus on this part:
const data = {
age: 18,
name: "John",
carRef: db.collection('cars').doc('john-car'),
}
await db.collection('users').doc('john').set(data);
You will have the ref in firestore. And in turn, VueFire will automatic bind the object.
For your case, i think you will need to find a way to get the db.collection('users').doc(last_edit_user_id) to make the ref for post.
My Firebase Cloud Function for my Realtime Database (NOT CloudStore) listens onWrite and provides a change object with before and after.
This documentation here states:
If fieldMask is set, then only fields that changed are present in before.
How do I set this fieldMask? And when I set this fieldMask, will the resulting before object have the JSON structure of only the changed fields?
I don't think that class you linked "ChangeJson" is supposed to be part of the public documentation. When using an onWrite trigger, you actually get a Change object, which is different. Pay attention to that instead, not ChangeJson.
Feel free to use the "Send feedback" link at the top right of any page of Firebase documentation indicate what your confusion was on that page.