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
The steps for uploading a single file are:
Request a link_hash
Define a Lens Account Template
Upload your file
Omitting an ACL Template will make the uploaded file immutable.
- 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>
You define an ACL template as follows that allows a Lens Account Owner or Manager to edit and delete the file.
import { AclTemplate } from "@lens-protocol/storage-node-client";
const acl: AclTemplate = { template: "lens_account", lensAccount: "0x6982508145454Ce325dDbE47a25d4ec3d2311933",};
In a submit event handler, you can upload the file as follows:
async function (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 file to the Lens Storage Nodes.
Multiple Files Upload
The steps for uploading multiple files are:
Request multiple link_hashes
Use the Lens Account Template
Add a folder index
Upload your files
Omitting an ACL Template will make the uploaded folder immutable.
- TS
- curl
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 { AclTemplate } from "@lens-protocol/storage-node-client";
const acl: AclTemplate = { template: "lens_account", lensAccount: "0x6982508145454Ce325dDbE47a25d4ec3d2311933",};
In a submit event handler, you can upload all files as follows:
async function (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.