You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(retrievedData.text()) // prints 'Bee is awesome!'
54
+
console.log(retrievedData.toUtf8()) // prints 'Bee is awesome!'
52
55
```
53
56
54
57
:::info Tip
@@ -60,48 +63,65 @@ A Swarm reference or hash is a 64 character long hex string which is the address
60
63
You can also upload files by specifying a filename. When you download the file, `bee-js` will return additional information like the `contentType` or `name` of the file.
console.log(retrievedFile.name) // prints 'textfile.txt'
67
-
console.log(retrievedFile.contentType) // prints 'application/octet-stream'
68
-
console.log(retrievedFile.data.text()) // prints 'Bee is awesome!'
75
+
console.log(retrievedFile.contentType) // prints 'application/x-www-form-urlencoded'
76
+
console.log(retrievedFile.data.toUtf8()) // prints 'Bee is awesome!'
69
77
```
70
78
71
79
In browsers, you can directly upload using the [`File` interface](https://developer.mozilla.org/en-US/docs/Web/API/File). The filename is taken from the `File` object itself, but can be overwritten through the second argument of the `uploadFile` function.
console.log(retrievedFile.name) // prints 'textfile.txt'
98
+
console.log(retrievedFile.contentType) // should print 'application/x-www-form-urlencoded
99
+
console.log(retrievedFile.data.toUtf8()) // prints the file content
84
100
```
85
101
86
102
### Files and Directories
87
103
88
104
In browsers, you can easily upload an array of `File` objects coming from your form directly with [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList). If the files uploaded through `uploadFiles` have a relative path, they are added relative to this filepath. Otherwise, the whole structure is flattened into single directory.
constBar=awaitbee.downloadFile(result.reference, './bar.txt') // download bar
99
119
100
-
console.log(rFoo.data.text()) // prints 'foo'
101
-
console.log(rBar.data.text()) // prints 'bar'
120
+
console.log(Foo.data.toUtf8()) // prints 'foo'
121
+
console.log(Bar.data.toUtf8()) // prints 'bar'
102
122
```
103
123
104
-
In NodeJS, you may utilize the `uploadFilesFromDirectory` function, which takes the directory path as input and uploads all files in that directory. Let's assume we have the following file structure:
124
+
You may also utilize the `uploadFilesFromDirectory` function, which takes the directory path as input and uploads all files in that directory. Let's assume we have the following file structure:
105
125
106
126
```sh
107
127
.
@@ -111,14 +131,17 @@ In NodeJS, you may utilize the `uploadFilesFromDirectory` function, which takes
0 commit comments