Lighthouse
  • 👋Introduction
  • Quick Start
  • How To
    • 🔑Create an API Key
    • 🔼Upload Data
      • 📁File
      • 🔤Text/JSON
      • 🔀Buffer
    • 🔒Upload Encrypted Data
      • 📁File
      • 🔤Text/JSON
      • 🔐Encryption Authentication
        • 📝Method 1: Signed Message
        • ⚕️Method 2: JWT
        • 📲Method 3: Passkey
    • Encryption Features
      • 👯Share File
      • ❌Revoke Access
      • 🔑Check Access Conditions
      • 🚪Token Gating
      • Chains Supported
      • 📃Access Control Conditions
      • 🔓Decrypt File
        • 🌐Browser Decrypt File
        • 💻NodeJS Decrypt File
      • 🚪Access control with zkTLS
      • 👬Account Delegation Tutorial
    • 📂List Files
    • 💁File Info
    • 💰Get Balance
    • 🔁Retrieve File
    • 💾Check for Filecoin Deals
    • 🔄IPNS - Handle Mutable Data
    • 📦Migrate Files
    • 📌Pin CID
    • 💸Pay per use
    • Resize Image
    • 💻Use CLI Tools
  • zkTLS
  • 🤝Account Delegation
  • 💾Filecoin First
    • Usage
    • 💰Pay Per Deal
  • Tutorials
    • 💸Pay to View Application
    • Use Python SDK
    • 📝Update Content with Lighthouse IPNS
    • 📹Add Video Player in UI
    • ✅Document Verification with PoDSI
    • 🎨Minting NFTs on EVM Chains
    • 🪙Minting NFTs on Solana
    • 👩‍💻Programmable Storage with Lighthouse SDK and Filecoin
    • 🔐Secure File Sharing
    • Upload Encrypted Files
    • 📄Token Gating and Custom Contract
    • 🔑Token Gating NFTs
    • 🏖️Pushing File Metadata Onchain
    • Use Radix Wallet on Lighthouse Filesdapp
  • Concepts
    • Glossary
    • IPFS CID Transition to v1
  • Support
    • 📞Contact
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. How To
  2. Upload Data

File

Any kind of file can be uploaded to Lighthouse refer to the code example given below. For developers building on other programming languages use the API directly.

Lighthouse currently allows a maximum file size of 24GB to be uploaded in a single request.

Method 1: NodeJS:

import lighthouse from '@lighthouse-web3/sdk'

/**
 * This function allows you to upload a file or a folder to Lighthouse.
 * 
 * @param {string} path - The location of your file or folder.
 * @param {string} apiKey - Your personal API key for Lighthouse.
 * @param {object} dealParameters - Custom parameters for file storage deals(check FVM section).
 * @return {object} - Returns details about the uploaded file.
*/
const uploadResponse = await lighthouse.upload(
  '/home/cosmos/Desktop/wow.jpg', 
  'YOUR_API_KEY_HERE'
)

console.log(uploadResponse)

/*Sample response
{
  data: {
    Name: 'wow.jpg',
    Hash: 'QmUHDKv3NNL1mrg4NTW4WwJqetzwZbGNitdjr2G6Z5Xe6s',
    Size: '31735'
  }
}
*/

Method 2: Browser

import React from "react"
import lighthouse from '@lighthouse-web3/sdk'

function App() {

  const progressCallback = (progressData) => {
    let percentageDone =
      100 - (progressData?.total / progressData?.uploaded)?.toFixed(2)
    console.log(percentageDone)
  }

  const uploadFile = async(file) =>{
    // Push file to lighthouse node
    // Both file and folder are supported by upload function
    // Third parameter is for multiple files, if multiple files are to be uploaded at once make it true
    // Fourth parameter is the deal parameters, default null
    const output = await lighthouse.upload(file, "YOUR_API_KEY", null, progressCallback)
    console.log('File Status:', output)
    /*
      output:
        data: {
          Name: "filename.txt",
          Size: 88000,
          Hash: "QmWNmn2gr4ZihNPqaC5oTeePsHvFtkWNpjY3cD6Fd5am1w"
        }
      Note: Hash in response is CID.
    */

      console.log('Visit at https://gateway.lighthouse.storage/ipfs/' + output.data.Hash)
  }

  return (
    <div className="App">
      <input onChange={e=>uploadFile(e.target.files)} type="file" />
    </div>
  )
}

export default App
curl -X POST -H 'Authorization: Bearer API_KEY' -F 'file=@/mnt/c/Users/ravis/Desktop/unnamed.jpeg' 'https://node.lighthouse.storage/api/v0/add'

The given command can be used to upload a file or directory on Lighthouse lighthouse-web3 upload <path>

PreviousUpload DataNextText/JSON

Last updated 8 months ago

Was this helpful?

🔼
📁