Features
Imagekit Integration for Media Storage

Imagekit Integration

using next's servers actions, it is best that we do not send the blob or base64 file directly to the backend, instead, we send it to imagekit, obtain the url of the image, and send that url to our backend to be saved in the database

Implementation

//Example with base64 file
const url =
  process.env.NODE_ENV === "development"
    ? "http://localhost:3000/api/utils/media"
    : `${constants.appUrl}/api/utils/media`;
 
let imageUrl;
 
await fetch(url, {
  method: "POST",
  body: JSON.stringify(fieldValue[0].data_url),
  headers: {
    "Content-Type": "application/json",
  },
})
  .then((response) => {
    return response.json();
  })
  .then((response) => {
    if (response) {
      imageUrl = response.url;
    }
  })
  .catch(() => {
    imageUrl = null;
  });