'How to get a public URL from MFS folder?

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)?



Solution 1:[1]

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 [email protected] 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!')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Transformer