Created
May 14, 2023 02:10
-
-
Save dabit3/056e4ad0ad36753ad25b72cc04e071b5 to your computer and use it in GitHub Desktop.
upload - upload component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const ipfs = ipfsClient(); // Connect to the local IPFS API | |
import { create } from 'ipfs-http-client' | |
import { Buffer } from 'buffer' | |
/* configure Infura auth settings */ | |
const projectId = "" | |
const projectSecret = "" | |
const auth = 'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64') | |
/* Create an instance of the client */ | |
const client = create({ | |
host: 'ipfs.infura.io', | |
port: 5001, | |
protocol: 'https', | |
headers: { | |
authorization: auth, | |
} | |
}) | |
export async function uploadJson(data) { | |
const added = await client.add(JSON.stringify(data)) | |
const uri = `ipfs://${added.path}` | |
console.log('uri: ', uri) | |
return uri | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment