Skip to content

alexbakers/ipfs-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

IPFS STORAGE API PROVIDERS

IPFS STORAGE API PROVIDERS

Examples

FILEBASE

fs.readFile(join(__dirname, "..", "banner.png"), async (err, data) => {
  if (err) {
    console.log("πŸ†˜ ERROR:", err);
    return;
  }

  if (!process.env.FILEBASE_KEY) {
    console.log("πŸ†˜ ERROR:", "Create .env file");
    return;
  }

  try {
    const url = await uploadFile.filebase(
      {
        key: process.env.FILEBASE_KEY,
        secret: process.env.FILEBASE_SECRET,
        bucket: process.env.FILEBASE_BUCKET,
      },
      {
        hash: "banner",
        ext: ".png",
        buffer: data,
      }
    );
    console.log("βœ… FILEBASE:", url);
    await deleteFile.filebase(
      {
        key: process.env.FILEBASE_KEY,
        secret: process.env.FILEBASE_SECRET,
        bucket: process.env.FILEBASE_BUCKET,
      },
      {
        hash: "banner",
        ext: ".png",
      }
    );
  } catch (err) {
    console.log("πŸ†˜ FILEBASE:", err);
  }
});

PINATA

fs.readFile(join(__dirname, "..", "banner.png"), async (err, data) => {
  if (err) {
    console.log("πŸ†˜ ERROR:", err);
    return;
  }

  if (!process.env.PINATA_JWT) {
    console.log("πŸ†˜ ERROR:", "Create .env file");
    return;
  }

  try {
    const url = await uploadFile.pinata(
      {
        jwt: process.env.PINATA_JWT,
      },
      {
        hash: "banner",
        ext: ".png",
        buffer: data,
      }
    );
    console.log("βœ… PINATA:", url);
    await deleteFile.pinata(
      {
        jwt: process.env.PINATA_JWT,
      },
      {
        url,
      }
    );
  } catch (err) {
    console.log("πŸ†˜ PINATA:", err);
  }
});

FLEEK

fs.readFile(join(__dirname, "..", "banner.png"), async (err, data) => {
  if (err) {
    console.log("πŸ†˜ ERROR:", err);
    return;
  }

  if (!process.env.FLEEK_KEY) {
    console.log("πŸ†˜ ERROR:", "Create .env file");
    return;
  }

  try {
    const url = await uploadFile.fleek(
      {
        key: process.env.FLEEK_KEY,
        secret: process.env.FLEEK_SECRET,
        bucket: process.env.FLEEK_BUCKET,
      },
      {
        hash: "banner",
        ext: ".png",
        buffer: data,
      }
    );
    console.log("βœ… FLEEK:", url);
    await deleteFile.fleek(
      {
        key: process.env.FLEEK_KEY,
        secret: process.env.FLEEK_SECRET,
        bucket: process.env.FLEEK_BUCKET,
      },
      {
        hash: "banner",
        ext: ".png",
      }
    );
  } catch (err) {
    console.log("πŸ†˜ FLEEK:", err);
  }
});

WEB3

fs.readFile(join(__dirname, "..", "banner.png"), async (err, data) => {
  if (err) {
    console.log("πŸ†˜ ERROR:", err);
    return;
  }

  if (!process.env.WEB3_TOKEN) {
    console.log("πŸ†˜ ERROR:", "Create .env file");
    return;
  }

  try {
    const url = await uploadFile.web3(
      {
        token: process.env.WEB3_TOKEN,
      },
      {
        hash: "banner",
        ext: ".png",
        buffer: data,
      }
    );
    console.log("βœ… WEB3:", url);
    await deleteFile.web3(
      {
        token: process.env.WEB3_TOKEN,
      },
      {
        url,
      }
    );
  } catch (err) {
    console.log("πŸ†˜ WEB3:", err);
  }
});

LIGHTHOUSE

fs.readFile(join(__dirname, "..", "banner.png"), async (err, data) => {
  if (err) {
    console.log("πŸ†˜ ERROR:", err);
    return;
  }

  if (!process.env.LIGHTHOUSE_TOKEN) {
    console.log("πŸ†˜ ERROR:", "Create .env file");
    return;
  }

  try {
    const url = await uploadFile.lighthouse(
      {
        token: process.env.LIGHTHOUSE_TOKEN,
      },
      {
        hash: "banner",
        ext: ".png",
        buffer: data,
      }
    );
    console.log("βœ… LIGHTHOUSE:", url);
    await deleteFile.lighthouse(
      {
        token: process.env.LIGHTHOUSE_TOKEN,
      },
      {
        url,
      }
    );
  } catch (err) {
    console.log("πŸ†˜ LIGHTHOUSE:", err);
  }
});

(c) Alex Baker