Reputation: 7
I think the problem lies in my backend here My backend is saving the files to my backend as the file name itself so like cat.jpg. also the images are saevd in the saem directory as the app in the userpics folder.
FRONTEND
<img className="w-56 h-56 border-2 border-gray-400 rounded-full" src={usersettings && userimg ? `/userpics/${userimg}` : imagepreview}>
</img>
@app.route("/getimg", methods=["POST", "GET"])
def getimg():
dataid = request.get_json()
user = User.query.filter_by(username=dataid['user']).first()
if user and user.userimg:
return user.userimg
else:
return jsonify({"error": "Image not found"}), 404
@app.route("/userpics/<filename>", methods=["POST", "GET"])
def get_user_image(filename):
# Serve the image from the static/userpics folder
return send_from_directory(os.path.join(app.root_path, "userpics"), filename)
Upvotes: -3
Views: 29