Comments (22)
Yeah, just a silly mistake, man.
Check this video👇
2023-12-24.20-13-57.mp4.mp4
from chai-backend.
Glad to help❤️
from chai-backend.
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.
now..if we change it to GET method...the error changes as we can see the change here
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.
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.
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.
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.
Yeah, you can send us the repo URL.
from chai-backend.
https://github.com/Talhaayub1/backend.git this is the repo!!!!
from chai-backend.
I will update you after checking.
from chai-backend.
Can you provide me the .env.sample file with only names of variables?
from chai-backend.
i didn't create .env.sample, i just create .env
from chai-backend.
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.
check this
from chai-backend.
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.
And, then you can see your api_secret.
from chai-backend.
got it man!! Thanks For this, resolve the issue 🙌❤️
from chai-backend.
brother can u help me?? solve this problem
from chai-backend.
thanks for your efforts . i do all this changes i cant fix the ploblem. i think i some line previously
from chai-backend.
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.
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.
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.
Great to hear this, I will verify this!!
from chai-backend.
Related Issues (20)
- missing Api to add videos in watchHistory
- not adding refersh token and access token in register route HOT 3
- Cannot POST /api/v1/users/register HOT 5
- Subscription controllers HOT 2
- Issue Occur in LogOut HOT 7
- MongoServerError: Invalid database name: HOT 5
- While doing API testing the logout is getting failed and getting Unauthorized request `Need Help` HOT 5
- getallvideos in video controller question HOT 2
- Issue logout user HOT 10
- Logout Issue HOT 3
- Cannot POST /api/v1/users/register HOT 7
- Using params
- accessToken -> undefine Solve this Problem
- Refresh token and Access token is not working HOT 1
- JWT malformed HOT 1
- Avatar Upload failed HOT 5
- i got multer error when i am upload the file
- coverImage undefined issue HOT 6
- Error in generating refresh and access token
- Error in connecting to DB after creating my first route. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chai-backend.