Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am building an API using ExpressJS.In one of the endpoints I need to create an account with an optional avatar.

So, I want to upload the avatar if avatar was provided before creating an account, but if no avatar was provided I just want to go ahead and still create the account.

I have the following code to check if avatar exists but it always returns undefined even though available.

    createAccount: async (req, res) => {
        let avatar = req.file.avatar;
        if (avatar) {
            console.log("Avatar Found");   //Even when I include avatar, I still get undefined here;
        } else {
            console.log("No Avatar Found");
        }
    },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...