Hello everyone,
You can use the kubo-rpc-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 kubo-rpc-client repository. Note that if you’ve previously used the ipfs-http-client
to upload content to IPFS, it was deprecated and we recommend using the kubo
client going forward.
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.
Also keep in mind that the kubo
client can only be imported as a module, so for simplicity save the below piece of code as an mjs
file, index.mjs
for example, before running it in node
.
import { urlSource, create } from 'kubo-rpc-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()