Skip to content

Commit

Permalink
Add note and update code for directory upload (#53)
Browse files Browse the repository at this point in the history
* Add code for app

* Update docs/tutorials/ipfs-browser-devenv/example/index.html

* Add note about update in Agregore that affects the tutorial

---------

Co-authored-by: RangerMauve <[email protected]>
  • Loading branch information
dirkcuys and RangerMauve authored Feb 6, 2024
1 parent ae8fc47 commit 3b822c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/examples/browser-devenv-v2/files/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ async function batchUpload(fileList, pathPrefix){
for (const file of batch){
formData.append('file', file)
}
let putUrl = [currentCid, pathPrefix, batchPath].join('/')
// let putUrl = [currentCid, pathPrefix, batchPath].join('/') // <-- uncomment this line if you are using Agregore < 2.4.0
let putUrl = [currentCid, pathPrefix].join('/') // <-- delete this line if you are using Agregore < 2.4.0
const resp = await fetch(putUrl, {method: 'put', body: formData})
currentCid = new URL(resp.headers.get('location')).origin
console.log(currentCid + (pathPrefix && '/') + pathPrefix)
Expand Down
5 changes: 4 additions & 1 deletion docs/tutorials/ipfs-dir-upload/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ const resp = await fetch(window.origin, {method: 'put', body: formData})

Unfortunately we can't upload files to different directories at the same time. This means that we need to find all the files that are in the same directory and upload them together. Let's look at an example directory structure:

**Update 2024-01-29**: since Agregore v2.4.0 the issue has been resolved and files in different folders can now be uploaded together. For the sanity of the writer, and the learning value of the thought process of implementing the solution the code below is updated to still work in v2.4.0, but not entirely reworked. A more sensible approach would be to create batches of a fixed size to upload files together.

```
- animals
- dogs
Expand Down Expand Up @@ -209,7 +211,8 @@ async function batchUpload(fileList, pathPrefix){
for (const file of batch){
formData.append('file', file)
}
let putUrl = [currentCid, pathPrefix, batchPath].join('/')
// let putUrl = [currentCid, pathPrefix, batchPath].join('/') // <-- uncomment this line if you are using Agregore < 2.4.0
let putUrl = [currentCid, pathPrefix].join('/') // <-- delete this line if using Agregore < 2.4.0
const resp = await fetch(putUrl, {method: 'put', body: formData})
currentCid = new URL(resp.headers.get('location')).origin
console.log(currentCid + (pathPrefix && '/') + pathPrefix)
Expand Down

0 comments on commit 3b822c6

Please sign in to comment.