3

So ipfs gives us https based urls for files yet they are all unique, per-file and hash based. I want to get something like that yet for expandable folders with updatable files (say have ‘parent hash/{fileIdPath}’ link). How to get a link to a file from the ipfs Mutable File System (MFS) (a link that would stay the same after I update the file)?

DuckQueen
  • 772
  • 10
  • 62
  • 134
  • 1
    This is a cool concept, but this isn't really a thing today in go-ipfs. You can get a CID for your MFS root, and as you know, that CID will change when you update your MFS. There's also IPNS, where you could get a single address, and update the CID that points to. You can also automate this process, and that sorta sounds like what you're asking for. If it is, I'm happy to write a full answer. – Discordian Jun 30 '22 at 21:48

1 Answers1

0

If I am understand the question you want to get access to the URL from a hash file path, please post your code so we can see what you have tried so far and what specifically is the issue

Here is a ref to IPFS

You will need a clients to access those resources over http

For e.g. ipfs-http-client, js-ipfs for js access

  1. using ipfs-http-client

please install it like so

//npm install ipfs-http-client@42.0.1 if you want a specific version
npm install --save ipfs-http-client

  1. Setup your permissions
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin  '["http://example.com"]'
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST", "GET"]'

Now you can access the information with client

const ipfs = window.IpfsHttpClient()

  1. sample js

With the JS client, install js-ipfs

import { create } from 'ipfs-http-client'
const client = create()
// add your addres below and get the contents
// dor e.g. const client = create(new URL('http://istart.work:1010'))
const client = create(new URL('http://127.0.0.1:1010'))
const { cid } = await client.add('Hello world!')
Transformer
  • 6,963
  • 2
  • 26
  • 52
  • No, my main and only problem is with folder contents creation\update: I want to get one base hash and many subfiles with addressing like on pin~ata in order to get something like `123hash/file1`, `123hash/file2` and have ability to add new files after to have `123hash/file4` for example – DuckQueen Apr 03 '22 at 20:02