@@ -33,7 +33,7 @@ Returns an array of [`BlobObject`](#blobobject).
3333
3434Returns a blob's data.
3535
36- ``` ts[ /api/blob /[...pathname\\ ].get.ts]
36+ ``` ts [server /api/files /[...pathname\\ ].get.ts]
3737export 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
6363Returns 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
8779Uploads a blob to the storage.
8880
89- ``` ts [server/api/upload .post.ts]
81+ ``` ts [server/api/files .post.ts]
9082export default eventHandler (async (event ) => {
9183 const { pathname } = getRouterParams (event )
9284 const form = await readFormData (event )
@@ -116,7 +108,7 @@ Returns a [`BlobObject`](#blobobject).
116108
117109Deletes a blob.
118110
119- ``` ts[ /api/blob /[...pathname\\ ].delete.ts]
111+ ``` ts [server /api/files /[...pathname\\ ].delete.ts]
120112export 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