diff --git a/docs/content/docs/2.storage/3.blob.md b/docs/content/docs/2.storage/3.blob.md index 7855069f..f2bb4e20 100644 --- a/docs/content/docs/2.storage/3.blob.md +++ b/docs/content/docs/2.storage/3.blob.md @@ -33,7 +33,7 @@ Returns an array of [`BlobObject`](#blobobject). Returns a blob's data. -```ts[/api/blob/[...pathname\\].get.ts] +```ts [server/api/files/[...pathname\\].get.ts] export default eventHandler(async (event) => { const { pathname } = getRouterParams(event) @@ -62,16 +62,8 @@ If you are fetching an image with a server route similar to the one above, you m Returns a blob's metadata. -```ts[/api/blob/[...pathname\\].head.ts] -export default eventHandler(async (event) => { - const { pathname } = getRouterParams(event) - - const blob = await useBlob().head(pathname) - - setHeader(event, 'x-blob', JSON.stringify(blob)) - - return sendNoContent(event) -}) +```ts +const blob = await useBlob().head(pathname) ``` #### Params @@ -86,7 +78,7 @@ Returns a [`BlobObject`](#blobobject). Uploads a blob to the storage. -```ts [server/api/upload.post.ts] +```ts [server/api/files.post.ts] export default eventHandler(async (event) => { const { pathname } = getRouterParams(event) const form = await readFormData(event) @@ -116,7 +108,7 @@ Returns a [`BlobObject`](#blobobject). Deletes a blob. -```ts[/api/blob/[...pathname\\].delete.ts] +```ts [server/api/files/[...pathname\\].delete.ts] export default eventHandler(async (event) => { const { pathname } = getRouterParams(event) @@ -139,24 +131,9 @@ Returns nothing. `ensureBlob()` is a handy util to validate a `Blob` by checking its size and type: -```ts [server/api/upload.post.ts] -export default eventHandler(async (event) => { - const form = await readFormData(event) - const file = form.get('file') as Blob - - if (!file || !file.size) { - throw createError({ - statusCode: 400, - message: 'No file provided' - }) - } - - // Will throw an error if the file is not an image or is larger than 1MB - ensureBlob(file, { maxSize: '1MB', types: ['image' ]}) - - // Save the image - return useBlob().put(`images/${file.name}`, file) -}) +```ts +// Will throw an error if the file is not an image or is larger than 1MB +ensureBlob(file, { maxSize: '1MB', types: ['image' ]}) ``` ### Params