# JavaScript addAll folder CID

**URL:** <https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558>\
**Category:** Help\
**Tags:** js-ipfs\
**Created:** [June 29, 2022, 10:46am UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558 "2022-06-29T10:46:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![KenRandall](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KenRandall](https://discuss.ipfs.tech/u/KenRandall)\
**Post date:** [June 29, 2022, 10:46am UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/1 "2022-06-29T10:46:02Z")

</div>

Hi,

I am using:

```js
const ipfs = await IpfsCore.create();
await ipfs.addAll(IPFSArray,{ pin: true, wrapWithDirectory: true});

```

How can I get the CID of the folder?

Thanks,

Ken

---

<div class="post-metadata">

**Author:** ![danieln](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/danieln/32/6408_2.png) [@danieln](https://discuss.ipfs.tech/u/danieln)\
**Post date:** [June 30, 2022, 9:48am UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/2 "2022-06-30T09:48:40Z")

</div>

Hey Ken,

The `add` or `addAll` method will return information about each file we’ve added, as well as details about any directory it had to create in order to add the files with the correct paths. In your example, the `addAll` method would return an array of `n+1` elements where `n` is the number of files in `IPFSArray`, one for each file added and another for the wrapping directory created.

Check out the [ProtoSchool](https://proto.school/regular-files-api/05) guide for more information.

---

<div class="post-metadata">

**Author:** ![KenRandall](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KenRandall](https://discuss.ipfs.tech/u/KenRandall)\
**Post date:** [June 30, 2022, 1:01pm UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/3 "2022-06-30T13:01:58Z")

</div>

Hi Daniel,

I do get that but the path is empty. for all of them. if I remove wrapWithDirectory I then get the path but obviously do not then get the extra one.

Thanks,

Ken

---

<div class="post-metadata">

**Author:** ![Discordian](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/discordian/32/4692_2.png) [@Discordian](https://discuss.ipfs.tech/u/Discordian)\
**Post date:** [June 30, 2022, 4:33pm UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/4 "2022-06-30T16:33:59Z")

</div>

> [@KenRandall](#):
>
> if I remove wrapWithDirectory I then get the path but obviously do not then get the extra one.

What are you trying to do?

```javascript
var ipfs;
async function main() {
	ipfs = await window.IpfsCore.create();
	const files = [{
		path: '/tmp/myfile.txt',
		content: 'ABC'
	},{
		path: 'tmp2',
		content: 'DEF'
	
	}];

	for await (const result of ipfs.addAll(files, {wrapWithDirectory: true})) {
		console.log(result);
	}
}
main()

```

This returns 4 objects, one with a blank path:

```auto
Object { path: "tmp/myfile.txt", cid: {…}, size: 11, mode: 420, mtime: undefined }
Object { path: "tmp2", cid: {…}, size: 11, mode: 420, mtime: undefined }
Object { path: "tmp", cid: {…}, size: 67, mode: 493, mtime: undefined }
Object { path: "", cid: {…}, size: 173, mode: 493, mtime: undefined }

```

`tmp/myfile.txt` contains “ABC”, `tmp2` contains “DEF”, `tmp` contains `myfile.txt` (which contains “ABC”), and the empty path contains `tmp` and `tmp2`. The corresponding CIDs for these are how you access the data inside of them. The path is empty because it’s the root directory wrapping all the contents specified, it’d be the same as the path being `/`.

Docs: [https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsaddallsource-options](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsaddallsource-options)

---

<div class="post-metadata">

**Author:** ![KenRandall](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KenRandall](https://discuss.ipfs.tech/u/KenRandall)\
**Post date:** [July 1, 2022, 4:12am UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/5 "2022-07-01T04:12:28Z")

</div>

Thanks. It looks like there is something wrong with the array I am creating. I’ll come back to you if I cannot resolve it.

---

<div class="post-metadata">

**Author:** ![KenRandall](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KenRandall](https://discuss.ipfs.tech/u/KenRandall)\
**Post date:** [July 2, 2022, 4:30am UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/6 "2022-07-02T04:30:05Z")

</div>

The problem I am having is that the content of the imagesI in the array I am trying to upload are base64 png’s. How can I upload these?

---

<div class="post-metadata">

**Author:** ![Discordian](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/discordian/32/4692_2.png) [@Discordian](https://discuss.ipfs.tech/u/Discordian)\
**Post date:** [July 2, 2022, 9:07pm UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/7 "2022-07-02T21:07:04Z")

</div>

You could convert the images from base64 to binary before you store them. Alternatively you could convert the images back from base64 after retrieval if base64 is a requirement for some reason.

If you need help with encoding/decoding, check out this article: [How To Encode and Decode Strings with Base64 in JavaScript | DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-encode-and-decode-strings-with-base64-in-javascript)

---

<div class="post-metadata">

**Author:** ![KenRandall](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KenRandall](https://discuss.ipfs.tech/u/KenRandall)\
**Post date:** [July 3, 2022, 9:15am UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/8 "2022-07-03T09:15:07Z")

</div>

Thanks. I managed to resolve this.

---

<div class="post-metadata">

**Author:** ![danieln](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/danieln/32/6408_2.png) [@danieln](https://discuss.ipfs.tech/u/danieln)\
**Post date:** [July 5, 2022, 10:18am UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/9 "2022-07-05T10:18:21Z")

</div>

How were you able to resolve this?

It’d be great if you can share your solution for others who may stumble across this issue.

---

<div class="post-metadata">

**Author:** ![KenRandall](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KenRandall](https://discuss.ipfs.tech/u/KenRandall)\
**Post date:** [July 18, 2022, 12:09pm UTC](https://discuss.ipfs.tech/t/javascript-addall-folder-cid/14558/10 "2022-07-18T12:09:48Z")

</div>

I had to use this function amd pass it the base64 string for each image I wanted to send

```auto
  function ConvData(Data) {
        var byteString = atob(Data.split(',')[1]);
        var ab = new ArrayBuffer(byteString.length);
        var ia = new Uint8Array(ab);
        for (var i = 0; i < byteString.length; i++) {
          ia[i] = byteString.charCodeAt(i);
        }
        return new Blob([ab], { type: "image/png" });
  }

```
