How to add internet content from a URL using ipfs-http-client

Hello everyone,

You can use the ipfs-http-client Javascript library to add internet content from a URL. In order to do so, please follow the below steps:
Install the library from the official ipfs-http-client.
Add the content to your Infura IPFS project using the URL source of a file on the internet or the URL of an already uploaded file on IPFS.
Don’t forget to use your Project ID and Project Secret.

const {ipfsClient, urlSource, create} = require('ipfs-http-client')
 
const projectId = '27…XXX';
const projectSecret = '20…XXX';
async function addUrl(){
  const auth =
    'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')
 
    const client =  create({
        host: 'ipfs.infura.io',
        port: 5001,
        protocol: 'https',
        headers: {
          authorization: auth
        }
      })
 
     const file = await client.add(urlSource('https://ipfs.io/ipfs/QmTCparuvt3dub5U3uFocjrqXbGhKoYZmT5Kf6y9tjzhR9?filename=lime_cay.jpg'))
        console.log(file)
     
}
 
addUrl()
3 Likes