GithubHelp home page GithubHelp logo

Comments (22)

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024 1

Yeah, just a silly mistake, man.
Check this video👇

2023-12-24.20-13-57.mp4.mp4

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024 1

Glad to help❤️

from chai-backend.

Divyanshu7001 avatar Divyanshu7001 commented on June 5, 2024 1

well..it is not a error actually...the users/register route is supposed to be a post route as we have written in our code..& due to that reason..the server cant get that route..cause it is actually supposed to be a POST method.
Screenshot 2023-12-25 021446

now..if we change it to GET method...the error changes as we can see the change here
Screenshot 2023-12-25 021649
Screenshot 2023-12-25 021724

The error changes as the users/register is now a GET method but no avatar has been given as input due to no frontend yet..and it gets a error of that portion.

hope this explanation helps you!!

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024

Hey, I think the condition you are writing for the avatar file is wrong.

Check the if condition once.

Additionally, you can provide me with the repo URL.

from chai-backend.

anishudupa avatar anishudupa commented on June 5, 2024

check for middleware once and check if you are accessing the file correctly (req.files not req.file)
check here - https://github.com/expressjs/multer
or else provide your source code repo link

from chai-backend.

Talhaayubkhan avatar Talhaayubkhan commented on June 5, 2024

Can you clone my repo? or did I send the link? because I checked everything but the avatar file is still throwing issue

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024

Yeah, you can send us the repo URL.

from chai-backend.

Talhaayubkhan avatar Talhaayubkhan commented on June 5, 2024

https://github.com/Talhaayub1/backend.git this is the repo!!!!

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024

I will update you after checking.

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024

Can you provide me the .env.sample file with only names of variables?

from chai-backend.

Talhaayubkhan avatar Talhaayubkhan commented on June 5, 2024

i didn't create .env.sample, i just create .env

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024

So, you have to create it or just provide me with a screenshot of the variable names.

Because I think I got your issue.

from chai-backend.

Talhaayubkhan avatar Talhaayubkhan commented on June 5, 2024
Screenshot 2023-12-24 191528

check this

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024

Hmm, I see.
Everything is fine.
Can you check the keys of Cloudinary once?
Because the problem comes with uploading the file to Cloudinary.

from chai-backend.

nirajchaurasiya avatar nirajchaurasiya commented on June 5, 2024

And, then you can see your api_secret.

from chai-backend.

Talhaayubkhan avatar Talhaayubkhan commented on June 5, 2024

got it man!! Thanks For this, resolve the issue 🙌❤️

from chai-backend.

AdityaHeree avatar AdityaHeree commented on June 5, 2024

brother can u help me?? solve this problem
Screenshot (75)
Screenshot (76)
Screenshot (78)
Screenshot (79)

from chai-backend.

AdityaHeree avatar AdityaHeree commented on June 5, 2024

thanks for your efforts . i do all this changes i cant fix the ploblem. i think i some line previously

from chai-backend.

itzmeimran avatar itzmeimran commented on June 5, 2024

Here dont use GET method instead use POST method as you are supposed to send files. Hope this ll help you fix error

from chai-backend.

shobitkhatri05 avatar shobitkhatri05 commented on June 5, 2024

Hello Brother @nirajchaurasiya I also the face same issue avatar is required Can you clone my repo? or did I send the link? because I checked everything but the avatar file is still throwing issue

from chai-backend.

RAMraghuram avatar RAMraghuram commented on June 5, 2024

Avatar is required issues

The issue is within the cloudinary.js file. When we are unlinking the local file path before sending the response, we should first check if the local file exists or not. As it is happening asynchronously, there is a chance that it is unlinking before all other tasks are completed. The best option would be to check if localFilePath exists, and then unlink it using the following code:

fs.existsSync(localFilePath) && fs.unlinkSync(localFilePath);

This is the final version:

import { v2 as cloudinary } from "cloudinary";
import fs from "fs";

cloudinary.config({
  cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
  api_key: process.env.CLOUDINARY_API_KEY,
  api_secret: process.env.CLOUDINARY_API_SECRET,
});

const uploadCloudinary = async (localFilePath) => {
  try {
    if (!localFilePath) return null;
    console.log("localFilePath", localFilePath);
    // upload file to cloudinary
    const response = await cloudinary.uploader.upload(localFilePath, {
      resource_type: "auto",
    });
    // file has been uploaded
    // console.log("File uploaded to cloudinary", response.url);
    fs.existsSync(localFilePath) && fs.unlinkSync(localFilePath);
    // console.log("response", response);
    return response;
  } catch (error) {
    fs.existsSync(localFilePath) && fs.unlinkSync(localFilePath); // remove file from local storage if cloudinary upload fails
    return null;
  }
};

export { uploadCloudinary };

from chai-backend.

akashsahaks avatar akashsahaks commented on June 5, 2024

Great to hear this, I will verify this!!

from chai-backend.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.