Skip to content

Instantly share code, notes, and snippets.

@rafinskipg
Created November 1, 2021 07:11
Show Gist options
  • Save rafinskipg/91d4a4447e871cb6b08a0e385e80f674 to your computer and use it in GitHub Desktop.
Save rafinskipg/91d4a4447e871cb6b08a0e385e80f674 to your computer and use it in GitHub Desktop.
type FileNft = {
path: string,
name: string
}
export async function storeDirectory(files: FileNft[]) {
try {
const client = new NFTStorage({
token: process.env.NFT_STORAGE_KEY as string,
});
const f = [];
for(var i = 0; i < files.length; i++) {
const file: FileNft = files[i]
console.log('Reading', file.path)
f.push(new File([fs.readFileSync(file.path)], file.name))
}
console.log('Storing')
return await client.storeDirectory(f);
} catch (e) {
console.error(e.message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment