Get Public IPFS gateway url easily.
- Via NPM :
npm i public-ipfs-gateway
- Via Yarn :
yarn add public-ipfs-gateway
- CJS :
const { getAllGateway, getLiveGateway, getAllLiveGateway } = require('public-ipfs-gateway')
- ESM :
import { getAllGateway, getLiveGateway, getAllLiveGateway } from 'public-ipfs-gateway'
import { getAllGateway } from 'public-ipfs-gateway';
// if use commonjs use this :
// const { getAllGateway } = require('public-ipfs-gateway');
// example url
const url = 'ipfs://bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg';
// example function for test
function test(){
console.log(getAllGateway(url));
}
test();
// result will be like
// [
// 'https://ipfs.io/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
// 'https://cloudflare-ipfs.com/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
// ...
// ]
import { getLiveGateway } from 'public-ipfs-gateway';
// if use commonjs use this :
// const { getLiveGateway } = require('public-ipfs-gateway');
// example url
const url = 'ipfs://bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg';
// example function for test
async function test(){
console.log(await getLiveGateway(url));
}
test();
// result will be like
// https://ipfs.io/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg
Default timeout is 3000ms, you can set custom timeout by add additional param like await getLiveGateway(url, 5000)
.
import { getAllLiveGateway } from 'public-ipfs-gateway';
// if use commonjs use this :
// const { getAllLiveGateway } = require('public-ipfs-gateway');
// example url
const url = 'ipfs://bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg';
// example function for test
async function test(){
console.log(await getAllLiveGateway(url));
}
test();
// result will be like
// [
// 'https://ipfs.io/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
// 'https://cloudflare-ipfs.com/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
// ...
// ]
Default timeout is 3000ms, you can set custom timeout by add additional param like await getLiveGateway(url, 5000)
.