8000 docs: improve blob · nuxt-hub/core@66d8c9e · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 66d8c9e

Browse files
committed
docs: improve blob
1 parent 998decf commit 66d8c9e

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

docs/content/docs/2.storage/3.blob.md

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Returns an array of [`BlobObject`](#blobobject).
3333

3434
Returns a blob's data.
3535

36-
```ts[/api/blob/[...pathname\\].get.ts]
36+
```ts [server/api/files/[...pathname\\].get.ts]
3737
export default eventHandler(async (event) => {
3838
const { pathname } = getRouterParams(event)
3939

@@ -62,16 +62,8 @@ If you are fetching an image with a server route similar to the one above, you m
6262

6363
Returns a blob's metadata.
6464

65-
```ts[/api/blob/[...pathname\\].head.ts]
66-
export default eventHandler(async (event) => {
67-
const { pathname } = getRouterParams(event)
68-
69-
const blob = await useBlob().head(pathname)
70-
71-
setHeader(event, 'x-blob', JSON.stringify(blob))
72-
73-
return sendNoContent(event)
74-
})
65+
```ts
66+
const blob = await useBlob().head(pathname)
7567
```
7668

7769
#### Params
@@ -86,7 +78,7 @@ Returns a [`BlobObject`](#blobobject).
8678

8779
Uploads a blob to the storage.
8880

89-
```ts [server/api/upload.post.ts]
81+
```ts [server/api/files.post.ts]
9082
export default eventHandler(async (event) => {
9183
const { pathname } = getRouterParams(event)
9284
const form = await readFormData(event)
@@ -116,7 +108,7 @@ Returns a [`BlobObject`](#blobobject).
116108

117109
Deletes a blob.
118110

119-
```ts[/api/blob/[...pathname\\].delete.ts]
111+
```ts [server/api/files/[...pathname\\].delete.ts]
120112
export default eventHandler(async (event) => {
121113
const { pathname } = getRouterParams(event)
122114

@@ -139,24 +131,9 @@ Returns nothing.
139131

140132
`ensureBlob()` is a handy util to validate a `Blob` by checking its size and type:
141133

142-
```ts [server/api/upload.post.ts]
143-
export default eventHandler(async (event) => {
144-
const form = await readFormData(event)
145-
const file = form.get('file') as Blob
146-
147-
if (!file || !file.size) {
148-
throw createError({
149-
statusCode: 400,
150-
message: 'No file provided'
151-
})
152-
}
153-
154-
// Will throw an error if the file is not an image or is larger than 1MB
155-
ensureBlob(file, { maxSize: '1MB', types: ['image' ]})
156-
157-
// Save the image
158-
return useBlob().put(`images/${file.name}`, file)
159-
})
134+
```ts
135+
// Will throw an error if the file is not an image or is larger than 1MB
136+
ensureBlob(file, { maxSize: '1MB', types: ['image' ]})
160137
```
161138

162139
### Params

0 commit comments

Comments
 (0)
0