Uploading Content
This guide will walk you through creating new content on the Lens Storage Nodes.
All uploaded contents are world-public readable. Privacy-settings will be implemented in the future.
Before Uploading
Are you uploading a single file or multiple files together ?
Do you want to make your files mutable (default: immutable) ?
Do you want to enable folder indexing (default: disabled)
Single File Upload (immutable)
If you just want to upload a file and make it immutable you can follow these steps:
- TS
- curl
Let's assume you have a form which allows to upload an image file.
<form id="upload-form"> <label for="files">Select a file:</label> <input type="file" name="file" accept="image/*" /> <button type="submit">Upload</button></form>
In a submit event handler, you can upload the file as follows:
async function onSubmit(event: SubmitEvent) { event.preventDefault();
const input = event.currentTarget.elements["file"];
const { uri } = await storageClient.uploadFile(input.files[0]);
console.log(uri); // lens://af5225b6262e03be6bfacf31aa416ea5e00ebb05e802d0573222a92f8d0677f5}
Single File Upload (mutable)
Omitting an ACL Template will make the uploaded file immutable.
The steps for uploading a single file which should become mutable are as follows:
- TS
- curl
Define an ACL template (Lens Account Template or Wallet Address Template or Generic Template)
Upload your file
Let's assume you have a form which allows to upload an image file.
<form id="upload-form"> <label for="files">Select a file:</label> <input type="file" name="file" accept="image/*" /> <button type="submit">Upload</button></form>
You define an ACL template as follows that allows a Lens Account Owner or Manager to edit and delete the file:
import { lensAccountOnly } from "@lens-protocol/storage-node-client";
const acl = lensAccountOnly("0x6982508145454Ce325dDbE47a25d4ec3d2311933");
Alernatively, you can use wallet based validations, and define an ACL template as follows that allows a given wallet to edit and delete the file:
import { walletOnly } from "@lens-protocol/storage-node-client";
const acl = walletOnly("0x6982508145454Ce325dDbE47a25d4ec3d2311933");
Another option is to use generic ACL validations where you can define an ACL template that specifies your custom ACL rules:
Generic ACL templates are currently only supported for contracts deployed on Lens Testnet (chain_id: 37111)
import { genericAcl } from "@lens-protocol/storage-node-client";
const acl = genericAcl("0x6982508145454Ce325dDbE47a25d4ec3d2311933", "is_allowed(address)", ["<recovered_address>"]);
In this ACL template, the function is_allowed() is called on the contract 0x6982508145454Ce325dDbE47a25d4ec3d2311933 and the signer's address is injected into the first function parameter as <recovered_address>. This is a reserved variable name which should not be changed or removed.
In a submit event handler, you can upload the file as follows:
async function onSubmit(event: SubmitEvent) { event.preventDefault();
const input = event.currentTarget.elements["file"];
const { uri } = await storageClient.uploadFile(input.files[0], { acl });
console.log(uri); // lens://af5225b6262e03be6bfacf31aa416ea5e00ebb05e802d0573222a92f8d0677f5}
That's it—you successfully uploaded your first mutable file to the Lens Storage Nodes.
Multiple Files Upload (mutable)
Omitting an ACL Template will make the uploaded folder and its files immutable.
The steps for uploading multiple files are:
- TS
- curl
Define an ACL template (Lens Account Template or Wallet Address Template or Generic Template)
Upload your files
Let's assume you have a form which allows to upload multiple images.
<form id="upload-form"> <label for="files">Select multiple files:</label> <input type="file" name="files" accept="image/*" multiple /> <button type="submit">Upload</button></form>
You define an ACL template as follows that allows a Lens Account Owner or Manager to edit and delete the folder.
import { lensAccountOnly } from "@lens-protocol/storage-node-client";
const acl = lensAccountOnly("0x6982508145454Ce325dDbE47a25d4ec3d2311933");
Alernatively, you can use wallet based validations, and define an ACL template as follows that allows a given wallet to edit and delete the file:
import { walletOnly } from "@lens-protocol/storage-node-client";
const acl = walletOnly("0x6982508145454Ce325dDbE47a25d4ec3d2311933");
Another option is to use generic ACL validations where you can define an ACL template that specifies your custom ACL rules:
Generic ACL templates are currently only supported for contracts deployed on Lens Testnet (chain_id: 37111)
import { genericAcl } from "@lens-protocol/storage-node-client";
const acl = genericAcl("0x6982508145454Ce325dDbE47a25d4ec3d2311933", "is_allowed(address)", ["<recovered_address>"]);
In this ACL template, the function is_allowed() is called on the contract 0x6982508145454Ce325dDbE47a25d4ec3d2311933 and the signer's address is injected into the first function parameter as <recovered_address>. This is a reserved variable name which should not be changed or removed.
In a submit event handler, you can upload all files as follows:
async function onSubmit(event: SubmitEvent) { event.preventDefault();
const input = event.currentTarget.elements["files"];
const { folder, files } = await storageClient.uploadFolder(input.files, { acl, index: true, });
console.log(folder.uri); // lens://af5225b6262… console.log(files[0].uri); // lens://47ec69ef75122…}
That's it—you successfully uploaded a folder to the Lens Storage Nodes.