Open heavenbean opened 1 year ago
import { globSource, create } from 'ipfs-http-client'; const projectId = '2...'; const projectSecret = '3...'; async function addFolder() { const auth = 'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64') const client = create({ host: 'ipfs.infura.io', port: 5001, protocol: 'https', apiPath: '/api/v0', headers: { authorization: auth } }) let options = { wrapWithDirectory: true, progress: (prog) => console.log(`received: ${prog}`) } let folderId = ''; for await (const file of client.addAll(globSource('../toupload', '**/*'), options)) { if (file && file.path && file.path === '') { folderId = file.cid; } } console.log('Uploaded to:', folderId); } addFolder()