This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,58 @@ Prints out objects like:
156
156
157
157
Now [ ipfs.io/ipfs/Qm...WW] ( https://ipfs.io/ipfs/QmNz1UBzpdd4HfZ3qir3aPiRdX5a93XwTuDNyXRc6PKhWW ) returns the "ABC" string.
158
158
159
+ ** Importing files from the file system:**
160
+
161
+ Both js-ipfs and js-ipfs-http-client export a utility to make importing files from the file system easier (Note: it not available in the browser).
162
+
163
+ ``` js
164
+ const IPFS = require (' ipfs' )
165
+ const { globSource } = IPFS
166
+
167
+ const ipfs = await IPFS .create ()
168
+
169
+ for await (const file of ipfs .add (globSource (' ./docs' , { recursive: true }))) {
170
+ console .log (file)
171
+ }
172
+
173
+ /*
174
+ {
175
+ path: 'docs/assets/anchor.js',
176
+ cid: CID('QmVHxRocoWgUChLEvfEyDuuD6qJ4PhdDL2dTLcpUy3dSC2'),
177
+ size: 15347
178
+ }
179
+ {
180
+ path: 'docs/assets/bass-addons.css',
181
+ hash: CID('QmPiLWKd6yseMWDTgHegb8T7wVS7zWGYgyvfj7dGNt2viQ'),
182
+ size: 232
183
+ }
184
+ ...
185
+ */
186
+ ```
187
+
188
+ ** Importing a file from a URL:**
189
+
190
+ Both js-ipfs and js-ipfs-http-client export a utility to make importing a file from a URL easier.
191
+
192
+ ``` js
193
+ const IPFS = require (' ipfs' )
194
+ const { globSource } = IPFS
195
+
196
+ const ipfs = await IPFS .create ()
197
+
198
+ for await (const file of ipfs .add (urlSource (' https://ipfs.io/images/ipfs-logo.svg' ))) {
199
+ console .log (file)
200
+ }
201
+
202
+ /*
203
+ {
204
+ path: 'ipfs-logo.svg',
205
+ cid: CID('QmTqZhR6f7jzdhLgPArDPnsbZpvvgxzCZycXK7ywkLxSyU'),
206
+ size: 3243
207
+ }
208
+ */
209
+ ```
210
+
159
211
A great source of [ examples] [ ] can be found in the tests for this API.
160
212
161
213
#### ` cat `
You can’t perform that action at this time.
0 commit comments