0

I'm creating a blog from scratch. I know firestore isn't the place to store images, but cloud storage is. I've learned you only need a reference to the images you store in cloud storage to retrieve them, but do i store the references belonging to a blog post in an array or a map in that blog post document in firestore? Or is there any better way to do it?

  • Whatever works best for your application. Since we don't know exactly how it works, it's difficult to know if there is a "correct" way. I suggesting just picking one that meets your needs, and go with it. – Doug Stevenson Apr 15 at 23:46
0

Storing images in the Cloud Storage blog, you have to consider if you want to include functionality to delete them.

If you will store them in the array, and then one of them will be deleted, to prevent another ones to change its reference, you could leave there some placeholder, i.e. "deleted".

So using concept like dictionary from python would be much more reasonable, so you do not mind order of the elements and its position:

images = {'image1': 'image1.jpg', 'image2', 'image2.jpg'}
file_img = images['image2']
with open(file_img, 'rb') as file:
    img = file.read()

Please keep in mind that Google Cloud Storage has some limitations for the NAMES of the stored objects:

  1. It can not be longer than 1024bytes when UTF-8 encoded
  2. Can not contain return or line feed
  3. Can not contain a dot "." or double dot ".."
  4. Should not contain control characters
  5. Should not use characters "#" or brackets "[", "]"

It is also reasonable to follow best practices for Google Cloud Storage in terms of Naming and Security: i.e. to avoid storing sensitive private data in the names of the objects, what object are accessed publicly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.