🎓 A1Learner
🔍
0 of 47 lessons completed

Blob and Object Storage

Blob storage is file storage that keeps each whole file as one object under a name called a key. A photo, a video and a backup can each sit in blob storage as a single object.

Three photos, one total

The store here is a plain mapping from key to size in KB. Storing 3 photos gives a combined total size.

store = {}
store["photos/cat.jpg"] = 200
store["photos/dog.jpg"] = 350
store["photos/bird.jpg"] = 150

for key in sorted(store):
    print(key, store[key], "KB")
print("total:", sum(store.values()), "KB")

Read one back by its key

A key names exactly one object. Asking for that key returns that object and no other.

store = {"photos/cat.jpg": 200, "photos/dog.jpg": 350,
         "photos/bird.jpg": 150}

print("objects stored:", len(store))
print("photos/dog.jpg is", store["photos/dog.jpg"], "KB")
print("photos/cat.jpg is", store["photos/cat.jpg"], "KB")

A whole file in one piece

One object holds a whole text file as a single value. Reading its key returns the file unchanged.

store = {}
store["notes/readme.txt"] = "Store files whole."

print("objects:", len(store))
print("read back:", store["notes/readme.txt"])
print("characters:", len(store["notes/readme.txt"]))

Example

store = {}
store["photos/beach.jpg"] = 200
store["photos/cake.jpg"] = 300
store["videos/party.mp4"] = 1200
store["backups/week1.zip"] = 800

for key in sorted(store):
    print(key, store[key], "KB")
total = sum(store.values())
print("total:", total, "KB")
print("total in MB:", total / 1000)
print("read back:", store["videos/party.mp4"], "KB")

Key points

  • Blob storage: a store for whole files, where each file is one object named by a key.
  • Object: one whole file kept in blob storage, such as one photo.
  • Key: the name that picks out one object, used to store it and read it back.
  • Use blob storage to hold the photos, videos and other files an app serves.

In this example, 4 objects are stored under 4 keys and their sizes add up to 2,500 KB, which is 2.5 MB. Reading one key back returns exactly that object's size.

Note

a database row splits one record into small fields, while an object keeps the whole file together in one piece.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

How does an app get one file out of blob storage?