https://github.com/bkawk/ipfs-api
Simple Image upload API for IPFS
https://github.com/bkawk/ipfs-api
Last synced: 11 months ago
JSON representation
Simple Image upload API for IPFS
- Host: GitHub
- URL: https://github.com/bkawk/ipfs-api
- Owner: bkawk
- License: mit
- Created: 2018-10-23T15:59:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-23T16:03:45.000Z (over 7 years ago)
- Last Synced: 2025-02-18T00:42:10.948Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Image to IPFS
A minimal API for saving and retrieving image data to/from IPFS
## Node & IPFS
First, make sure you have NPM (packaged with [Node.js](https://nodejs.org)) installed. Run `npm install` to install your element's dependencies, then run `polymer serve` to serve your element locally. Also, ensure you IPFS installed and the daemon running [IPFS](https://ipfs.io/docs/install/)
## Start the server
```
$ npm run now
```
## Saving data to IPFS
Currently, there are no size or domain restrictions, text-based data can be stored on IPFS by making a POST request to
```
/ipfs
```
the body should contain an object with the key of 'data' and the value containing URI Encoded base 64 value you want to save, in this example we are storing a 1px transparent gif as a base 64 string.
```
{"data":"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="}
```
the response is an object with success and hash keys
```
{
"success": true,
"hash": "QmczMXpyKH2msqMEYC9dD9YcvPAAkeB4GUBNxcue52rCVH"
}
```
## Getting data from IPFS
To get data from IPFS you can make a GET request containing the IPFS Hash you wish to get
```
/ipfs/QmczMXpyKH2msqMEYC9dD9YcvPAAkeB4GUBNxcue52rCVH
```
The response is an object with success and data keys
```
{
"success": true,
"data": "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
}
```
## Getting Image SRC Data
Getting image src data is possible to allow direct loading of images
```
/img/QmczMXpyKH2msqMEYC9dD9YcvPAAkeB4GUBNxcue52rCVH
```
The response is just the data, no object is returned.
```
data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==
```