IPFS in react native

I’m able to connect to ipfs http client in react native. How to add an image using ipfs http client? I tried ipfs.add(imageData), didn’t work.

Sorry you’re having problems - could you post a full snippet of the code you are using? Any error message that appears would also be helpful.

Have you read over the IPFS 101 example?

import ipfsClient from 'ipfs-http-client';

const ipfs = ipfsClient({host: 'localhost:5001', port: '5001'});

const upload = async (base64) => {
    const results = await ipfs.add(base64);

    for await (const item of results) {


I got nothing, no error.

Maybe try with host being ‘localhost’ instead of ‘localhost:5001’?

const ipfs = ipfsClient({host: 'localhost:5001', port: '5001'})

You can use the multiaddr too:

const ipfs = ipfsClient('/ip4/')

I’m able to connect. I’m not sure if I upload an image correctly. Do you know how?

Apart from the host thing, your code looks correct.

I think you have to do some additional work to get ipfs-http-client running under react native though: https://github.com/ipfs/js-ipfs/issues/2840#issuecomment-573035578

There’s also a tracking issue to have it running properly under react native: https://github.com/ipfs/js-ipfs/issues/2813

1 Like