REST API for adding files to IPFS
Go to file
Chris Grimmett 5d958c6674 bump ver 2024-01-01 04:40:36 -08:00
.env.example update docs 2023-12-22 01:05:03 -08:00
.gitignore init 2023-12-21 02:45:16 -08:00
.nvmrc init 2023-12-21 02:45:16 -08:00
README.md use plain text instead of JSON 2024-01-01 03:53:51 -08:00
app.json use healtcheck 2023-12-22 00:26:09 -08:00
index.js fix missing message 2024-01-01 04:40:05 -08:00
package.json bump ver 2024-01-01 04:40:36 -08:00
pnpm-lock.yaml progress 2023-12-22 00:13:54 -08:00

README.md

link2cid

Motivation

I wish I could give kubo or IPFS cluster a URI to a file and then they would download the file and add to ipfs, returning me a CID.

However, neither kubo nor IPFS cluster can do this.

link2cid solves this issue with a REST API for adding a file at url to IPFS.

Usage

Configure environment

Create a .env file. See .env.example for an example. Important environment variables are API_KEY, PORT, and IPFS_URL.

Install and run

pnpm install
pnpm start

Make a GET REST request to /add with url as a query parameter. Expect a SSE response.

Examples

HTTPIE

http -A bearer -a $API_KEY --stream 'http://localhost:3939/add?url=https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png' Accept:text/event-stream
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream; charset=utf-8
Date: Thu, 21 Dec 2023 11:20:24 GMT
Transfer-Encoding: identity
X-Powered-By: Express

:ok

event: dlProgress
data: {
    "percent": 100
}

event: addProgress
data: {
    "percent": 100
}

event: end
data: {
    "cid": "bafkreidj3jo7efguloaixz6vgivljlmowagagjtqv4yanyqgty2hrvg6km"
}

Javascript

@todo this is incomplete/untested

await fetch('http://localhost:3939/add?url=https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png', {
    headers: {
        'accept': 'text/event-stream',
        'authorization': `Bearer ${API_KEY}`
    }
});

Dev notes

Generate API_KEY

require('crypto').randomBytes(64).toString('hex')

TypeError: data.split is not a function

If you see this error, make sure data in SSE event payload is a string, not a number.