2023-06-19 15:07:25 +00:00
# IPFS File Manager
2023-06-20 18:01:54 +00:00
This repository contains JavaScript code to interact with IPFS (InterPlanetary File System). It provides functionalities to add and retrieve files from IPFS.
2023-06-19 15:07:25 +00:00
2023-06-20 22:36:02 +00:00
## Installation
Before running the code, make sure you have Node.js installed in your development environment. You can download it from the official Node.js website: [https://nodejs.org ](https://nodejs.org )
To install the necessary dependencies, navigate to the project directory and run the following command:
```bash
npm install
```
This will install the required packages specified in the `package.json` file.
## Usage
### Adding a File to IPFS
2023-06-19 15:07:25 +00:00
2023-06-20 18:01:54 +00:00
To add a file to IPFS, use the following code:
2023-06-19 15:07:25 +00:00
```javascript
2023-06-20 22:36:02 +00:00
import IPFSFileUploader from './IPFSFileUploader.js';
2023-06-19 15:07:25 +00:00
2023-06-20 22:36:02 +00:00
const ipfsUploader = new IPFSFileUploader();
2023-06-19 15:07:25 +00:00
2023-06-20 22:36:02 +00:00
const filePath = './file.txt'; // Replace with the path of the file you want to add to IPFS
ipfsUploader.uploadFileToIPFS(filePath);
2023-06-19 15:07:25 +00:00
```
2023-06-20 18:01:54 +00:00
Make sure to replace `filePath` with the path of the file you want to add to IPFS.
2023-06-19 15:07:25 +00:00
2023-06-20 22:36:02 +00:00
### Retrieving a File from IPFS
2023-06-19 15:07:25 +00:00
2023-06-20 18:01:54 +00:00
To retrieve a file from IPFS, use the following code:
2023-06-19 15:07:25 +00:00
```javascript
2023-06-20 22:36:02 +00:00
import IPFSFileRetriever from './IPFSFileRetriever.js';
2023-06-19 15:07:25 +00:00
2023-06-20 22:36:02 +00:00
const ipfsRetriever = new IPFSFileRetriever();
2023-06-20 18:01:54 +00:00
const cid = 'QmQgGxzWnzjCfouxRiozBiEG3wcsuJGWjtHjv3wurVbJ9s'; // Replace with the CID of the file you want to retrieve
const filepath = './retrievedFile'; // Specify the file path without the extension
2023-06-20 22:36:02 +00:00
ipfsRetriever.retrieveFileFromIPFS(cid, filepath);
2023-06-19 15:07:25 +00:00
```
2023-06-20 18:01:54 +00:00
Make sure to replace `cid` with the CID of the file you want to retrieve from IPFS.
2023-06-19 15:07:25 +00:00
2023-06-20 18:01:54 +00:00
## Notes
2023-06-19 15:07:25 +00:00
2023-06-20 22:36:02 +00:00
- The code depends on the IPFS package for Node.js. It will be installed automatically when you run `npm install` .
- The code uses the `fs/promises` module for file operations, which is available in Node.js version 14.0.0 and above.
- Additional dependencies such as `file-type` may be required for file type determination. They will also be installed automatically.
2023-06-19 15:07:25 +00:00
2023-06-20 18:01:54 +00:00
Feel free to explore and modify the code according to your needs.