> For the complete documentation index, see [llms.txt](https://easonwang.gitbook.io/web_advance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easonwang.gitbook.io/web_advance/distribute-web/ipfs-project.md).

# IPFS project

## IPFS 教學

Tutorial

<https://github.com/ipfs/js-ipfs/tree/master/examples>

### 安裝

<https://ipfs.io/docs/install/>

Linux <https://gist.github.com/MiguelBel/b3b5f711aa8d9362afa5f16e4e972461>

```
sudo apt-get update
sudo apt-get install golang-go -y
wget https://dist.ipfs.io/go-ipfs/v0.4.10/go-ipfs_v0.4.10_linux-386.tar.gz
tar xvfz go-ipfs_v0.4.10_linux-386.tar.gz
sudo mv go-ipfs/ipfs /usr/local/bin/ipfs
```

### 初始化

```
ipfs init
ipfs daemon
```

上傳

```
// 檔案
ipfs add <file path>

// 資料夾
ipfs add -r ./
```

下載

```
ipfs get <file hash>
```

也可在以下網站查看

```
https://ipfs.io/ipfs/檔案Hash
```

可以輸入以下進入節點資訊頁面

```
localhost:5001/webui
```

## JS-IPFS

js 版本的IPFS

(目前在windows無法正常使用)

上傳

```javascript
const IPFS = require('ipfs')
const fs = require('fs');

const node = new IPFS()
node.on('ready', () => {
  node.files.add({
    path: '',
    content: fs.createReadStream('./sample.txt')
  }, (err, result) => {
    if (err) { throw err }

    console.log('\nAdded file:', result[0].path, result[0].hash)
    // process.exit()
  })
})
```

下載

```javascript
const IPFS = require('ipfs');

const multihashStr  = 'QmT4sfBdFcEiNbRh2FZfyX8jmFBr41qzKLkL75xYXG36aC';

const node  = new IPFS();

node.on('ready', () => {
node.files.get(multihashStr, function (err, stream) {
  stream.on('data', (file) => {
    // write the file's path and contents to standard out
    try {
     console.log(file);
    } catch(e) {
     console.log('錯誤是' + e)
    }
  })
})
});
```

記得要寫上以下 抓取錯誤

```javascript
node.on('error', (err) => {console.log(err)})
```

有時會出現以下錯誤

```
Error: can't lock file /home/.jsipfs/repo.lock: has non-zero size
```

刪除該lock檔案即可


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://easonwang.gitbook.io/web_advance/distribute-web/ipfs-project.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
