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
Copy file name to clipboardExpand all lines: docs/build/components/http-headers.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,6 @@ The `headers` is an array of objects, each containing `key` and `value`, and the
44
44
45
45
- The `Content-Type` header is calculated automatically and cannot be altered.
46
46
- No validation or check for uniqueness is performed. For example, if a header matches a file based on multiple rules, multiple headers will be set.
47
-
- Likewise, if you provide the same header when you [upload](https://juno.build/docs/build/storage#upload-asset) file to your "Storage" and within the configuration, both headers will be set in the response.
47
+
- Likewise, if you provide the same header when you [upload](https://juno.build/docs/build/storage#upload-file) file to your "Storage" and within the configuration, both headers will be set in the response.
Copy file name to clipboardExpand all lines: docs/build/storage/development.mdx
+93-8Lines changed: 93 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,11 @@ import ClientSide from "../components/client-side.mdx";
8
8
9
9
---
10
10
11
-
## Upload asset
11
+
## Upload file
12
12
13
-
To upload an asset, use the following code:
13
+
When you upload a file, it becomes an **asset** stored in the Storage of your Satellite. Assets are accessible over the web and can be listed, deleted, or protected using tokens.
14
+
15
+
To upload a file, use the following code:
14
16
15
17
```typescript
16
18
import { uploadFile } from"@junobuild/core";
@@ -21,7 +23,9 @@ const result = await uploadFile({
21
23
});
22
24
```
23
25
24
-
The `data` parameter is the file you want to upload. This is typically selected using an HTML `<input type="file" /> ` element.
26
+
#### Parameters
27
+
28
+
The `data` parameter is the file you want to upload. This is a `Blob`, typically selected using an HTML `<input type="file" />` element.
25
29
26
30
The `uploadFile` function provides various options, including:
27
31
@@ -38,7 +42,36 @@ The `uploadFile` function provides various options, including:
38
42
39
43
:::
40
44
41
-
### Protected asset
45
+
#### Returns
46
+
47
+
The function returns the uploaded asset key as an object with the following fields:
48
+
49
+
-`fullPath`: The unique path to the asset. Example: `/images/myimage.jpg`.
50
+
-`name`: The name of the asset (typically the filename). Example: `myimage.jpg`.
51
+
-`downloadUrl`: The URL to access the asset on the web or to download it. This URL can be used in a browser or embedded directly in HTML elements like `<img>` or `<a>`.
52
+
53
+
---
54
+
55
+
## Upload blob
56
+
57
+
The `uploadBlob` function works like [`uploadFile`](#upload-file) but does **not** infer the filename from the data.
58
+
You must explicitly provide the `filename`.
59
+
60
+
```typescript
61
+
import { uploadBlob } from"@junobuild/core";
62
+
63
+
const result =awaituploadBlob({
64
+
data: newBlob([myBuffer]),
65
+
filename: "generated.jpg",
66
+
collection: "images"
67
+
});
68
+
```
69
+
70
+
This is useful when uploading raw binary data that wasn't selected via a file input.
71
+
72
+
---
73
+
74
+
## Protected assets
42
75
43
76
While all assets can be found on the internet, it is possible to make their URL difficult to guess so that they remain undiscoverable (**as long as they are not shared**) and considered "private".
The function requires a collection and accepts various optional parameters, including a matcher (a regex applied to the assets fullPaths and descriptions), pagination options, and sorting order.
77
110
@@ -225,7 +258,7 @@ The function returns the assets and various information, in the form of an objec
225
258
226
259
```typescript
227
260
{
228
-
items: []; // The data - array of assets
261
+
items: []; // The data - array of assets without their content
229
262
items_length: bigint; // The number of assets - basically items.length
230
263
items_page?:bigint; // If the query is paginated, at what page (starting from 0) do the items find the place
231
264
matches_length: bigint; // The total number of matching results
@@ -235,6 +268,58 @@ The function returns the assets and various information, in the form of an objec
235
268
236
269
---
237
270
271
+
## Download URL
272
+
273
+
The `downloadUrl` function is used to generate a public URL for accessing a specific asset stored on a Satellite.
274
+
275
+
:::note
276
+
277
+
You get similar information directly from the result of an upload.
278
+
This function can be used to generate the URL on the fly.
279
+
280
+
:::
281
+
282
+
This URL can be used to:
283
+
284
+
- Open the file directly in a browser
285
+
- Embed the asset in HTML elements such as `<img src="...">` or `<a href="...">`
286
+
- Trigger a download when used in an `<a href="..." download>` link
287
+
288
+
```typescript
289
+
import { downloadUrl } from"@junobuild/core";
290
+
291
+
const url =downloadUrl({
292
+
assetKey: {
293
+
fullPath: "/images/logo.png",
294
+
token: "a-secret-token"// optional
295
+
}
296
+
});
297
+
298
+
// Example usage
299
+
<imgsrc={url} alt="Logo"/>
300
+
```
301
+
302
+
#### Parameters
303
+
304
+
-**`assetKey`** (required)
305
+
-**`fullPath`**: The full path to the asset (e.g., `/images/file.jpg`).
306
+
-**`token`** (optional): A secret token used to access protected assets.
307
+
308
+
-**`satellite`** (optional)
309
+
Required only in Node.js environments to specify which Satellite to use.
310
+
311
+
#### Returns
312
+
313
+
- A `string` representing the full URL to access the asset.
314
+
315
+
:::note
316
+
317
+
If a `token` is provided when uploading the asset, it must also be included in the URL to access it. This makes the asset effectively private until shared with the token.
318
+
319
+
:::
320
+
321
+
---
322
+
238
323
## Count assets
239
324
240
325
The `countAssets` function is used to count the number of assets in a specified collection without retrieving the actual assets.
This function accepts similar parameters as the `listAssets` function, including `collection`, `matcher`, and `owner`, and returns the count of matching documents.
253
338
@@ -304,7 +389,7 @@ import { deleteFilteredAssets } from "@junobuild/core";
Copy file name to clipboardExpand all lines: docs/examples/angular.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,5 +125,5 @@ The following functions from `@junobuild/core` are used in this example:
125
125
|`listDocs`| List documents in a collection |[`src/app/services/docs.service.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/services/docs.service.ts)|[List documents](../build/datastore/development#list-documents)|
126
126
|`setDoc`| Create or update a document |[`src/app/components/modal/modal.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/modal/modal.component.ts)|[Add a document](../build/datastore/development#add-a-document)|
127
127
|`deleteDoc`| Delete a document |[`src/app/components/delete/delete.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/delete/delete.component.ts)|[Delete a document](../build/datastore/development#delete-a-document)|
128
-
|`uploadFile`| Upload a file to storage |[`src/app/components/modal/modal.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/modal/modal.component.ts)|[Upload asset](../build/storage/development#upload-asset)|
128
+
|`uploadFile`| Upload a file to storage |[`src/app/components/modal/modal.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/modal/modal.component.ts)|[Upload file](../build/storage/development#upload-file)|
129
129
|`deleteAsset`| Delete a file from storage |[`src/app/components/delete/delete.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/delete/delete.component.ts)|[Delete asset](../build/storage/development#delete-asset)|
Copy file name to clipboardExpand all lines: docs/examples/nextjs.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,5 +125,5 @@ The following functions from `@junobuild/core` are used in this example:
125
125
|`listDocs`| List documents in a collection |[`src/components/table.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/table.tsx)|[List documents](../build/datastore/development#list-documents)|
126
126
|`setDoc`| Create or update a document |[`src/components/modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/modal.tsx)|[Add a document](../build/datastore/development#add-a-document)|
127
127
|`deleteDoc`| Delete a document |[`src/components/delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/delete.tsx)|[Delete a document](../build/datastore/development#delete-a-document)|
128
-
|`uploadFile`| Upload a file to storage |[`src/components/modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/modal.tsx)|[Upload asset](../build/storage/development#upload-asset)|
128
+
|`uploadFile`| Upload a file to storage |[`src/components/modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/modal.tsx)|[Upload file](../build/storage/development#upload-file)|
129
129
|`deleteAsset`| Delete a file from storage |[`src/components/delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/delete.tsx)|[Delete asset](../build/storage/development#delete-asset)|
Copy file name to clipboardExpand all lines: docs/examples/react-javascript.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,5 +133,5 @@ The following functions from `@junobuild/core` are used in this example:
133
133
|`listDocs`| List documents in a collection |[`src/components/Table.jsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-example/src/components/Table.jsx)|[List documents](../build/datastore/development#list-documents)|
134
134
|`setDoc`| Create or update a document |[`src/components/Modal.jsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-example/src/components/Modal.jsx)|[Add a document](../build/datastore/development#add-a-document)|
135
135
|`deleteDoc`| Delete a document |[`src/components/Delete.jsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-example/src/components/Delete.jsx)|[Delete a document](../build/datastore/development#delete-a-document)|
136
-
|`uploadFile`| Upload a file to storage |[`src/components/Modal.jsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-example/src/components/Modal.jsx)|[Upload asset](../build/storage/development#upload-asset)|
136
+
|`uploadFile`| Upload a file to storage |[`src/components/Modal.jsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-example/src/components/Modal.jsx)|[Upload file](../build/storage/development#upload-file)|
137
137
|`deleteAsset`| Delete a file from storage |[`src/components/Delete.jsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-example/src/components/Delete.jsx)|[Delete asset](../build/storage/development#delete-asset)|
Copy file name to clipboardExpand all lines: docs/examples/react-typescript.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,5 +129,5 @@ The following functions from `@junobuild/core` are used in this example:
129
129
|`listDocs`| List documents in a collection |[`src/components/Table.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-ts-example/src/components/Table.tsx)|[List documents](../build/datastore/development#list-documents)|
130
130
|`setDoc`| Create or update a document |[`src/components/Modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-ts-example/src/components/Modal.tsx)|[Add a document](../build/datastore/development#add-a-document)|
131
131
|`deleteDoc`| Delete a document |[`src/components/Delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-ts-example/src/components/Delete.tsx)|[Delete a document](../build/datastore/development#delete-a-document)|
132
-
|`uploadFile`| Upload a file to storage |[`src/components/Modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-ts-example/src/components/Modal.tsx)|[Upload asset](../build/storage/development#upload-asset)|
132
+
|`uploadFile`| Upload a file to storage |[`src/components/Modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-ts-example/src/components/Modal.tsx)|[Upload file](../build/storage/development#upload-file)|
133
133
|`deleteAsset`| Delete a file from storage |[`src/components/Delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/react-ts-example/src/components/Delete.tsx)|[Delete asset](../build/storage/development#delete-asset)|
Copy file name to clipboardExpand all lines: docs/examples/sveltekit.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,5 +126,5 @@ The following functions from `@junobuild/core` are used in this example:
126
126
|`listDocs`| List documents in a collection |[`src/lib/components/Table.svelte`](https://github.com/junobuild/create-juno/blob/main/templates/sveltekit-example/src/lib/components/Table.svelte)|[List documents](../build/datastore/development#list-documents)|
127
127
|`setDoc`| Create or update a document |[`src/lib/components/Modal.svelte`](https://github.com/junobuild/create-juno/blob/main/templates/sveltekit-example/src/lib/components/Modal.svelte)|[Add a document](../build/datastore/development#add-a-document)|
128
128
|`deleteDoc`| Delete a document |[`src/lib/components/Delete.svelte`](https://github.com/junobuild/create-juno/blob/main/templates/sveltekit-example/src/lib/components/Delete.svelte)|[Delete a document](../build/datastore/development#delete-a-document)|
129
-
|`uploadFile`| Upload a file to storage |[`src/lib/components/Modal.svelte`](https://github.com/junobuild/create-juno/blob/main/templates/sveltekit-example/src/lib/components/Modal.svelte)|[Upload asset](../build/storage/development#upload-asset)|
129
+
|`uploadFile`| Upload a file to storage |[`src/lib/components/Modal.svelte`](https://github.com/junobuild/create-juno/blob/main/templates/sveltekit-example/src/lib/components/Modal.svelte)|[Upload file](../build/storage/development#upload-file)|
130
130
|`deleteAsset`| Delete a file from storage |[`src/lib/components/Delete.svelte`](https://github.com/junobuild/create-juno/blob/main/templates/sveltekit-example/src/lib/components/Delete.svelte)|[Delete asset](../build/storage/development#delete-asset)|
Copy file name to clipboardExpand all lines: docs/examples/vanilla-javascript.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,5 +127,5 @@ The following functions from `@junobuild/core` are used in this example:
127
127
|`listDocs`| List documents in a collection |[`src/components/table.js`](https://github.com/junobuild/create-juno/blob/main/templates/vanilla-js-example/src/components/table.js)|[List documents](../build/datastore/development#list-documents)|
128
128
|`setDoc`| Create or update a document |[`src/components/modal.js`](https://github.com/junobuild/create-juno/blob/main/templates/vanilla-js-example/src/components/modal.js)|[Add a document](../build/datastore/development#add-a-document)|
129
129
|`deleteDoc`| Delete a document |[`src/components/delete.js`](https://github.com/junobuild/create-juno/blob/main/templates/vanilla-js-example/src/components/delete.js)|[Delete a document](../build/datastore/development#delete-a-document)|
130
-
|`uploadFile`| Upload a file to storage |[`src/components/modal.js`](https://github.com/junobuild/create-juno/blob/main/templates/vanilla-js-example/src/components/modal.js)|[Upload asset](../build/storage/development#upload-asset)|
130
+
|`uploadFile`| Upload a file to storage |[`src/components/modal.js`](https://github.com/junobuild/create-juno/blob/main/templates/vanilla-js-example/src/components/modal.js)|[Upload file](../build/storage/development#upload-file)|
131
131
|`deleteAsset`| Delete a file from storage |[`src/components/delete.js`](https://github.com/junobuild/create-juno/blob/main/templates/vanilla-js-example/src/components/delete.js)|[Delete asset](../build/storage/development#delete-asset)|
Copy file name to clipboardExpand all lines: docs/examples/vue.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,5 +127,5 @@ The following functions from `@junobuild/core` are used in this example:
127
127
|`listDocs`| List documents in a collection |[`src/components/Table.vue`](https://github.com/junobuild/create-juno/blob/main/templates/vue-example/src/components/Table.vue)|[List documents](../build/datastore/development#list-documents)|
128
128
|`setDoc`| Create or update a document |[`src/components/Modal.vue`](https://github.com/junobuild/create-juno/blob/main/templates/vue-example/src/components/Modal.vue)|[Add a document](../build/datastore/development#add-a-document)|
129
129
|`deleteDoc`| Delete a document |[`src/components/Delete.vue`](https://github.com/junobuild/create-juno/blob/main/templates/vue-example/src/components/Delete.vue)|[Delete a document](../build/datastore/development#delete-a-document)|
130
-
|`uploadFile`| Upload a file to storage |[`src/components/Modal.vue`](https://github.com/junobuild/create-juno/blob/main/templates/vue-example/src/components/Modal.vue)|[Upload asset](../build/storage/development#upload-asset)|
130
+
|`uploadFile`| Upload a file to storage |[`src/components/Modal.vue`](https://github.com/junobuild/create-juno/blob/main/templates/vue-example/src/components/Modal.vue)|[Upload file](../build/storage/development#upload-file)|
131
131
|`deleteAsset`| Delete a file from storage |[`src/components/Delete.vue`](https://github.com/junobuild/create-juno/blob/main/templates/vue-example/src/components/Delete.vue)|[Delete asset](../build/storage/development#delete-asset)|
0 commit comments