Can someone please help me to understand the best way to set up a designated asset canister for storing photos/videos in Motoko?
It is my understanding that the default asset canister which is configured to work with the @dfinity/assets npm package can only store up to 1 GiB of data. I only am seeing documentation on how to upload assets to it, but have no idea what it is supposed to look like on the backend. Say we wanted to use it to store user specific assets such as their profile picture. How can we authenticate on a per user basis? How do we know when the canister is almost full? How can we then create a new canister when it is almost full? Anyone have any experience storing files at scale and on a per user basis in these asset canisters?
Is there a better way to make use of stable memory structures like a Trie to be able to store up to 400 GiB of images/videos in a single canister? If we did something like this, would it be possible to query an image/video using a publicly exposed ICP URL?
1 Like
For storing assets in a canister in Motoko, I can suggest this repo for a simple data store and this concerning asset certification.
In Motoko you can check the caller of any query/update call. HOWEVER, if you do the requests via HTTP then everyone will be the anonymous identity. So either you fetch the bytes through an agent and then turn that into a picture, or you gate on the frontend, which isnāt secure, but a lot more convenient.
The canister can check its own memory usage, e.g. with ExperimentalStableMemory.size
1 Like
Thank you for the response. Do you know of a good way to implement a system which can dynamically create asset canisters? Essentially a smart contract that is used for management of asset canisters. So if one asset canister gets full it knows to create a new one and can return the canister id for storage from the frontend?
I donāt have an example to point to, but if the spawning canister checks for canister_status
regularly using a timer then it should be pretty straightforward
1 Like
I am thinking I want to create a asset canister network to act as a shared infinitely scalable storage solution. Essentially, there is a master canister which using the WASM of a standard asset canister can spin up asset canisters. The master canister is also responsible for keeping a record of all the asset canisters and tracking whether they are āavailableā or āfullā.
The master canister can also grant individual application users with the āPrepareā permission to allow users to propose an asset upload to a designated asset canister. Then the master canister (which has admin access to all asset canisters) can commit the prepare request. Essentially, all asset canisters are controlled by the master canister to ensure that application users can not freely upload to or delete other peoples assets.
Do you think this would work?
Yes, that should work. Side note: I still have not gotten around to make the asset canister use stable memory. So the space available per canister is pretty low (~2GB)
1 Like