@@ -33,7 +33,7 @@ Returns an array of [`BlobObject`](#blobobject).
33
33
34
34
Returns a blob's data.
35
35
36
- ``` ts[ /api/blob /[...pathname\\ ].get.ts]
36
+ ``` ts [server /api/files /[...pathname\\ ].get.ts]
37
37
export default eventHandler (async (event ) => {
38
38
const { pathname } = getRouterParams (event )
39
39
@@ -62,16 +62,8 @@ If you are fetching an image with a server route similar to the one above, you m
62
62
63
63
Returns a blob's metadata.
64
64
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 )
75
67
```
76
68
77
69
#### Params
@@ -86,7 +78,7 @@ Returns a [`BlobObject`](#blobobject).
86
78
87
79
Uploads a blob to the storage.
88
80
89
- ``` ts [server/api/upload .post.ts]
81
+ ``` ts [server/api/files .post.ts]
90
82
export default eventHandler (async (event ) => {
91
83
const { pathname } = getRouterParams (event )
92
84
const form = await readFormData (event )
@@ -116,7 +108,7 @@ Returns a [`BlobObject`](#blobobject).
116
108
117
109
Deletes a blob.
118
110
119
- ``` ts[ /api/blob /[...pathname\\ ].delete.ts]
111
+ ``` ts [server /api/files /[...pathname\\ ].delete.ts]
120
112
export default eventHandler (async (event ) => {
121
113
const { pathname } = getRouterParams (event )
122
114
@@ -139,24 +131,9 @@ Returns nothing.
139
131
140
132
` ensureBlob() ` is a handy util to validate a ` Blob ` by checking its size and type:
141
133
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' ]})
160
137
```
161
138
162
139
### Params
0 commit comments