Netlify Dynamic Site Challenge : Building blob playground with Netlify Blob
Tags: netlifychallenge, devchallenge, webdev, javascript
Published: 2024-05-07 12:52:24

*This is a submission for the [Netlify Dynamic Site Challenge](https://dev.to/challenges/netlify): Build with Blobs.*


## What I Built
I implemented a file upload feature in an Angular application, allowing users to store files in Netlify Blobs storage. Users can upload files, which are then stored in the Netlify Blobs store. Additionally, I integrated Netlify Functions to handle processing tasks, enabling efficient retrieval and management of blob objects, including metadata handling.

## Demo
{% embed https://img-playground.netlify.app/blob-playground %}

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/690zv89wq14rqta4zggj.png)


## Platform Primitives

- **Angular Application**: I've created an Angular application as the front end for interacting with the Netlify Blobs.

- **File Upload Feature**: Users can upload files through the Angular application's interface. This involves creating a form with a file input field and handling the file submission in the Angular component.

- **Netlify Blob Storage Integration**: I've integrated Netlify Blobs into the Angular application. This includes setting up the necessary configurations to interact with the Netlify Blobs API provided by Netlify. To use the Netlify Blobs API, first install the `@netlify/blobs` module using the

```javascript
npm install @netlify/blobs
```

- **Storing Files as Blobs**: Upon file upload, the Angular application converts the file into an object and sets it into the Netlify Blobs. This involves making API requests to Netlify Blob storage endpoints. First we will get store after that we will setJson into it.

```javascript
 const mystore = getStore("your-store-name");
 await mystore.setJSON("file-1", { type: "file", filesize: "10kb" });
```

- **Retrieving Files**: Users can retrieve files stored in the Netlify Blobs through your Angular application. This involves making API requests to fetch Blob objects from Netlify Blobs and rendering them appropriately in the application interface.
```typescript
 const mystore = getStore("your-store-name");
 const entry1 = await my store.get("file-1");
 console.log(entry1) //you will get the above setjson value
```

- **Metadata Handling**: The application handles metadata associated with the uploaded files. This might include storing additional information like file name, file size, upload timestamp, etc., along with the Blob object in the storage.
```typescript
//set(key, value, { metadata? })
const mystore = getStore("your-store-name");
 await mystore.setJSON("file-1", { type: "file", fileData: "xyz" }, {metadata: { name: "font.png", type: "image/png", size: "1.2 KiB" });
```

- **Integration with Netlify Functions**: I've integrated Netlify Functions into project for processing tasks related to Blobs. This could include tasks like file manipulation, set metadata, or any other custom operations you need to perform on the Blobs.

```command
npm install @netlify/functions
```

```typescript
import type { Context } from "@netlify/functions"

export default async (req: Request, context: Context) => {
  return new Response("Hello, world!")
}
```

{% embed  https://dev.to/chintanonweb/netlify-dynamic-site-challenge-building-a-dynamic-image-gallery-with-netlify-image-cdn-3n53 %}
{% embed https://dev.to/chintanonweb/netlify-dynamic-site-challenge-building-news-article-cache-management-playground-4f4a %}