Storage
All files in Unia are stored using a simple API:
world.storage.set(arrayBuffer) -> Promise {status: 'okay', key: 'string'}
world.storage.get(key) -> Promise ArrayBuffer | null
Each file you upload returns a deterministic hash key, which you can then use for referencing the file. You can use this storing 3D models, audio, images, zipped assets etc.
Once a file it is uploaded, it's key and contents are permanent. If you want to store modifiable data see: Database
Examples
Downloading a JSON object
const buffer = await world.storage.get("key");
const decoder = new TextDecoder();
const u8 = new Uint8Array(buffer);
const jsonData = JSON.parse(decoder.decode(u8));
Storing a JSON object
const data = JSON.stringify({ very: "meaowy" });
const encoder = new TextEncoder();
const buffer = encoder.encode(data).buffer;
const result = await world.storage.set(buffer);
if (result.status == "okay") {
data["assetname"] = result.key;
}
Uploading any file using the browser file input
const saveFile = async (event) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = async (e) => {
const arrayBuffer = e.target.result;
let result = await world.storage.set(arrayBuffer);
// the key can be used for downloading the asset later
// key is a unique ID, based on hash of the arrayBuffer
console.log(result.key);
};
reader.readAsArrayBuffer(file);
};
const importFile = document.createElement("input");
importFile.type = "file";
importFile.setAttribute("type", "file");
importFile.addEventListener("change", saveFile, false);
this.click = () => {
importFile.click();
};
Internally this storage is used for project assets, and is used for things like:
const video = Video("assetVideoName.mp4");
const avatar = Model("Rindo.vrm");
These files are cached locally using IndexedDB.
Your files
You can export your app and all it's files, for self hosting info see local deployment.
For info on storage authentication see authentication.
Low latency network
Unia runs a distributed network of servers across the U.S., Tokyo, Australia, Europe, New Zealand and Singapore. Files are served via Nginx sendfile on 10Gbps connections, resulting in very low latency.