javascriptnode.jscloudinaryhttp-status-code-204

getting options 204 while using cloudinary api resources


I am using cloudinary to fetch my images and everything works fine but it sends a 204 preflight res when using cloudinary and when i remove cloudinary logic it works normal.

login Controller

    const gender = await getGender(username);
    
    const profileImage = await getProfileImage(gender);

    //creating a new user
    const newUser = new User({
      username,
      email,
      password: hashedPassword,
      gender,
      profileImage,
    });

    //saving the user to the database
    await newUser.save();
    console.log("hello");
    //returning the new created user in the response
    return res.status(201).json({ message: "Registration Successful" });

getPofileImage function

export const getProfileImage = async (gender: string) => {
  try {
    // fetching image according to the user's gender
    const response = await cloudinary.api.resources({
      type: "upload",
      prefix: `e-com/images/${gender}`,
    });
    return response.resources[
      Math.floor(Math.random() * response.resources.length)
    ].url;
  } catch (error) {
    return "https://pbs.twimg.com/media/FGCpQkBXMAIqA6d?format=jpg&name=large";
  }
};

I was expecting a 201 response with {message:"Registration Successful"} but instead of that i am getting 204 with nothing.


Solution

  • In your getProfileImage, you are using cloudinary.api.resources. This is an Admin API that is designed for back-end operation and also rate limited.

    Could you explain the use case a little more? Perhaps you could use tagging with client side list API and achieve the same result? When you do this, you get the following advantages: