Parameters
idstringWhich storage. Leave it out for the account's default.
const target = await api.storage.get(); // the default
const one = await api.storage.get({ id }); // a particular onetarget = api.storage.get() # the default
one = api.storage.get(id=storage_id) # a particular oneIt answers null rather than throwing
An unknown id, a malformed one, or one belonging to another account all give null. So the check is a value test, not a try/catch — and null never means « it is someone else's ».
const storage = await api.storage.get({ id });
if (!storage) {
throw new Error("that storage is not on this account");
}storage = api.storage.get(id=storage_id)
if storage is None:
raise LookupError("that storage is not on this account")This, or getStorage()
| api.storage.get() | api.getStorage() | |
|---|---|---|
| Gives | A ConnectedStorage, with methods | Four plain fields |
| Use it to | read, write, list files | show which one is the default |
| Takes an id | yes | no — always the default |
What you can do with what comes back
const storage = await api.storage.get({ id });
// Any storage: read and write through run()
await storage.run({ action: "collections" });
// A computer only: its own files, on that machine
const pc = await api.storage.get({ id: computerId });
await pc.files.list();storage = api.storage.get(id=storage_id)
# Any storage: read and write through run()
storage.run(action="collections")
# A computer only: its own files, on that machine
pc = api.storage.get(id=computer_id)
pc.files.list()files and terminals exist only on a computer
Reaching for them on anything else throws storage_not_local, and on a phone storage_is_phone — its files are in its browser. Test type before you reach.
if (storage.type === "filesystem") {
await storage.files.list();
} else {
await storage.run({ action: "objects" });
}if storage.type == "filesystem":
storage.files.list()
else:
storage.run(action="objects")What it carries
| Field | Is |
|---|---|
| id · label | Identity, and the display name. |
| type | filesystem · phone · browser · database · object |
| provider · managedBy | What is behind it, and who operates it. |
| service | nosql · sql · object on an IaGenify Cloud storage; null otherwise. |
| isDefault | Whether a save with no target goes here. |
| machineId · hostname · deviceId | On a device: which one. |
Nothing here carries a credential: what you supplied at connection is used by the server and not handed back.