Is it possible to link from firebasestorage to firestoredatabase? - firebase

Is there a way to link a picture from storage to firestore like this way: "homepage/aposto.png"? Or do you have to copy the complete url?

There is no built-in linkage. You would have to store a string that represents the path to the image. You can also store strings in the metadata of a storage object if you want to link it back to the database in some way.

Related

Is base64 a good option for encoding custom Document IDS for Firestore?

I am working on creating some users in my firebase app and I would like to provide custom user ids as they are authenticating with an external service.
For example my user ID generation is consisted by 2 parts like so:
AuthService:AuthServiceUsername
That can look in reality like:
Instragram:dimitrioskanellopoulos
But I dont like to have this string used as a user id so I encode it to base64 like so:
const uid = Buffer.from(`instagram:${serviceUserID}`).toString('base64');
Is there any risk for me doing that ? Is base64 ok to be used also in regards to query params?
Firestore document IDs are quite flexible on what's allowed and not. See https://firebase.google.com/docs/firestore/quotas#limits.
But base64 would actually not be safe, since it contains /, which is disallowed in Firestore document IDs

CollectionFS cfs:dropbox How get url to image after uploading?

I published my whole folder with images, but how generate automatically url in my code for each image?
Just use url method. From CollectionFs docs
url
Returns the HTTP file URL for the current FS.File.
Specify a store attribute to get the URL for a specific store. If you
don't specify the store name, the URL will be for the copy in the
first defined store.
If you use several stores (for example I'm using file store for thumbs and S3 for full images for one collection), then define store or it returns first store url.

Does morphia support GridFS?

Is there a implementation of GridFS in Morphia? How is this?
I am using a webservice and receive base64 input, which is transform in a bit array, such like this:
private bit [] image;
I created my model class to communicate with morphia, however, each document of that collection will have a lot of images, is something like an event has a lot of editions and an edition has its images.
How can I mapped that attribute in morphia?
GridFS is not yet supported by Morphia, if you want to store information into GridFS from your application you need to use the native Java GridFS API ( see https://github.com/mongodb/mongo-java-driver/blob/master/src/test/com/mongodb/gridfs/GridFSTest.java )
To answer your question
How can I mapped that attribute in morphia?
The code you have written will work, and your images will be saved as bytes into the document, in the attribute "image" like any other attribute. As you probably know MongoDB & Morphia are using BSON in memor, on the network and in the database, this means it will save the bytes as they are sent.
So of you still want to store the image in the document, not an issue at all if they are small, you just have to be careful about the overall size of the document. As you probably know a document cannot exceed 16Mb.

Display DB blob type in Flex

My Mysql database stores images (in PNG, JPG)of our personnel and it's field type is set to longblob.
Is there any possibility to load blob data type using HttpService and render it in Image component in Flex .??? ^..^
I'm eager to know about as it comes in handy in the nearest future!!!
You can, but I don't see the point of storing your images in a DB.
Simplest way to get it into an Image is to load the blob, convert to a ByteArray which you can set as the source of of said Image.
If you override HttpService you can use it to receive binary data. If you don't want to override HttpService you have the option of encoding you binary data in base64 before sending it.
But if have the option to store the images in a directory on the server and just send links to the client - that would be a better solution.

Best Practice for Saving Images

I am allowing users of the admin panel of my website to upload photos, its a simple process where I check the validity of the image and then save it to a folder, then I also have to record a couple of database records for that image to be able to retrieve it later, my saving function is as follows...
The function that uploads and saves the picture in the folder with a name i construct in another function:
My_HTMLInputFile.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("~/photos\" & pta.FileName))
And the function that creates the database record for that same picture:
Public Function InsertPhoto() As Integer
Dim pta As New GKPTableAdapters.tblPhotosTableAdapter
Return pta.InsertPhoto(PhotoCaption, PhotoDescription, ("http://www.myURL.com/photos/" & FileName), IsDefault, IsPicture)
End Function
Now I know that what I am doing is full of best-practices violations, so please point me out to what I should do, keep in mind that the users might delete the pictures later, so I wanna make sure that I can delete the database and file of the picture, and the whole issue of the path is confusing me :P
Thanks in advance.
Something I've noticed right off the bet is that you are hardcoding the FULL PATH to the image.
I'd just store the image name, and then prepend the relative path when i display it in the application
If you allow your users to delete the files via your application, you should delete the record in the database, and then delete the file itself by using File.Delete method
You may also want to look at your file name generation. If you use an md5 hash of the image data as the file name, for example, you can prevent people from uploading duplicate images and you also don't have to think of a way to generate "unique" names for the images.
Exposing your photos directory directly to the internet may be a bad idea if there are images in there that the public should not see and your naming policy is predictable. People will start guessing image URLs and stumble upon something they are not allowed to see.

Resources