0

I'm playing around with ipfs and made a small playground with the following:

const IPFS = require('ipfs-api');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https'});
const fs = require('fs');

let buf;


let file = fs.readFileSync('./test.png');

ipfs.files.add(file, (err, result) => {
    if (err) {
        console.log(err);
        return;
    } else {
        console.log(result[0].hash)
        return result[0].hash;
    }
})

When this snippet runs it uploads a file to https://ipfs.io/ipfs/{result[0].hash}.

This is my first time working with IPFS so I have some follow-up (I think) simple questions:

  • How can I add a trailing slash to the url if I want to "bundle" multiple files under the same ipfs url? For example, if I had two files I wanted to upload, the url should instead be https://ipfs.io/ipfs/{result[0].hash}/1 for file one and https://ipfs.io/ipfs/{result[0].hash}/2 for file 2
  • If I wanted to upload say, 500 images in a space of two days (250 today, 250 tomorrow), if the first 250 were stored following .../1 .../2 .../3 etc in the url with the same hash, could anyone potentially find the hash and use it to store their own data from .../250 to .../500? If I send the ipfs url to anyone (therefore making the hash public) would other people be able to upload to it as well?
  • Are these urls persistent and non-changing? From my understanding, every hash is different and no url will actually "expire" because it's all stored in the blockchain. But I have come across mentions of "backing up ipfs data". From my understanding, some tutorials I've seen mention pinata so I assume it's for this purpose.

Thank you in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.