@@ -39,3 +39,129 @@ BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => {
39
39
```
40
40
41
41
This example sets up a local HTTP server using the Bunny Edge Scripting SDK to list files on a Storage Zone using the BunnyCDN Storage SDK. You can access the server at 127.0.0.1:8080 and observe the real-time request logs.
42
+
43
+ ### Quick Start
44
+
45
+ - [ list] ( #listing-files )
46
+ - [ delete] ( #remove-files-or-directory )
47
+ - [ upload] ( #uploading-a-file )
48
+ - [ download] ( #download-a-file )
49
+
50
+ #### Getting a file
51
+
52
+ When getting a file, you can either get the metadata of a file, or the content
53
+ of the file.
54
+
55
+ The metadata describe the file.
56
+
57
+ ``` typescript
58
+ import * as BunnyStorageSDK from " @bunny.net/storage-sdk" ;
59
+
60
+ let storageZone = BunnyStorageSDK .zone .connect_with_accesskey (BunnyStorageSDK .regions .StorageRegion .Falkenstein , " storage-zone-name" , " token" )
61
+ let obj = await BunnyStorageSDK .file .get (storageZone , " /my-folder/my-file" );
62
+
63
+ /*
64
+ * Here obj will be equal to something like this:
65
+ const obj = {
66
+ Guid: '123',
67
+ UserId: 'user1',
68
+ LastChanged: '2023-01-01T00:00:00Z',
69
+ DateCreated: '2022-01-01T00:00:00Z',
70
+ StorageZoneName: 'test-zone',
71
+ Path: '/test/path',
72
+ ObjectName: 'test-file.txt',
73
+ Length: 100,
74
+ StorageZoneId: 1,
75
+ IsDirectory: false,
76
+ ServerId: 1,
77
+ Checksum: 'abc123',
78
+ ReplicatedZones: 'UK,NY',
79
+ ContentType: 'text/plain',
80
+ data: () => Promise<{
81
+ stream: ReadableStream<Uint8Array>;
82
+ response: Response;
83
+ length?: number;
84
+ }>,
85
+
86
+ };
87
+ */
88
+ ```
89
+
90
+ From this metadata, you can then download the file content by using ` await obj.data() ` .
91
+
92
+ #### Listing files
93
+
94
+ You can list and navigate accross your storage zone by using:
95
+
96
+ ``` typescript
97
+ let list = await BunnyStorageSDK .file .list (sz , " /" );
98
+ ```
99
+
100
+ This will give you a list of file Metadata you'll be able to navigate.
101
+
102
+ #### Uploading a file
103
+
104
+ To upload a file, we leverage ** Streams** to upload files as it would allow you
105
+ to upload files without having the full stream of content available.
106
+
107
+ ``` typescript
108
+ export async function upload(storageZone : StorageZone .StorageZone , path : string , stream : ReadableStream <Uint8Array >, options ? : UploadOptions ): Promise <boolean >;
109
+ export async function upload(storageZone : StorageZone .StorageZone , path : string , stream : ReadableStream <Uint8Array >): Promise <boolean >;
110
+ export async function upload(storageZone : StorageZone .StorageZone , path : string , stream : ReadableStream <Uint8Array >, options ? : UploadOptions ): Promise <boolean >;
111
+
112
+ export type UploadOptions = {
113
+ /**
114
+ * The SHA256 Checksum associated to the data you want to send. If null then
115
+ * the server will automatically calculate it.
116
+ */
117
+ sha256Checksum? : string ;
118
+ /**
119
+ * You can override the content-type of the file you upload with this option.
120
+ */
121
+ contentType? : string ;
122
+ };
123
+ ```
124
+
125
+ Example:
126
+
127
+ ``` typescript
128
+ await BunnyStorageSDK .file .upload (sz , " /some-file" , random_bytes_10kb );
129
+ ```
130
+
131
+ #### Download a file
132
+
133
+ To downlaod a file, you have two choices, either you use this function to
134
+ download it directly.
135
+
136
+ ``` typescript
137
+ export async function download(storageZone : StorageZone .StorageZone , path : string ): Promise <{
138
+ stream: ReadableStream <Uint8Array >;
139
+ response: Response ;
140
+ length? : number ;
141
+ }>;
142
+ ```
143
+
144
+ Example:
145
+
146
+ ``` typescript
147
+ await BunnyStorageSDK .file .download (sz , " /some-file" );
148
+ ```
149
+
150
+ You'll have the stream of the content and the associated response and the length
151
+ if available.
152
+
153
+ You could also use the ` data ` function available in the File Metadata.
154
+
155
+ #### Remove files or directory
156
+
157
+
158
+ ``` typescript
159
+ export async function remove(storageZone : StorageZone .StorageZone , path : string ): Promise <boolean >;
160
+ export async function removeDirectory(storageZone : StorageZone .StorageZone , path : string ): Promise <boolean >;
161
+ ```
162
+
163
+ Example:
164
+
165
+ ``` typescript
166
+ await BunnyStorageSDK .file .remove (sz , " /some-file" );
167
+ ```
0 commit comments