πFile Info
Use file info API to get metadata of your file stored at Lighthouse.
const fileInfo = async() => {
/*
@param {string} cid - cid of file.
*/
const cid = "QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh"
const fileInfo = await lighthouse.getFileInfo(cid)
/* Sample Response
{
data: {
fileSizeInBytes: '95077',
cid: 'QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh',
encryption: false,
fileName: 'itachi.jpg',
mimeType: 'image/jpeg',
txHash: ''
}
}
*/
}curl https://api.lighthouse.storage/api/lighthouse/file_info?cid=QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHhfrom lighthouseweb3 import Lighthouse
# Initialize Lighthouse (token not required for getFileInfo)
lh = Lighthouse(token="YOUR_API_KEY")
# Get file information
cid = "QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh"
file_info = lh.getFileInfo(cid)
print(file_info)
# Sample Response
# {
# 'data': {
# 'fileSizeInBytes': '95077',
# 'cid': 'QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh',
# 'encryption': False,
# 'fileName': 'itachi.jpg',
# 'mimeType': 'image/jpeg',
# 'txHash': ''
# }
# }
# Access individual values
print(f"File Name: {file_info['data']['fileName']}")
print(f"File Size: {file_info['data']['fileSizeInBytes']} bytes")
print(f"CID: {file_info['data']['cid']}")
print(f"MIME Type: {file_info['data']['mimeType']}")
print(f"Encryption: {file_info['data']['encryption']}")package main
import (
"context"
"fmt"
"log"
"os"
"github.com/lighthouse-web3/lighthouse-go-sdk/lighthouse"
)
func main() {
client := lighthouse.NewClient(nil,
lighthouse.WithAPIKey(os.Getenv("LIGHTHOUSE_API_KEY")),
)
ctx := context.Background()
cid := "QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh"
fileInfo, err := client.Files().Info(ctx, cid)
if err != nil {
log.Fatal(err)
}
fmt.Printf("File Name: %s\n", fileInfo.FileName)
fmt.Printf("File Size: %d bytes\n", fileInfo.FileSizeInBytes)
fmt.Printf("CID: %s\n", fileInfo.CID)
fmt.Printf("MIME Type: %s\n", fileInfo.MimeType)
fmt.Printf("Encryption: %v\n", fileInfo.Encryption)
}Last updated
Was this helpful?