I want to upload images to the server by using python flask in a fixed location by using the following code.
UPLOAD_FOLDER = 'F:\Coursera\React_Flask\SocialNetwork\Frontend\Api'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
_file = request.files['file']
filename = secure_filename(_file.filename)
target = os.path.join(UPLOAD_FOLDER, 'image')
if not os.path.isdir(target):
os.mkdir(target)
source = "/".join([target, filename])
_file.save(source)
Image is uploaded the corresponding folder. Then I try to display the image in react frontend by the following way but nothing display.
<img src={'../../../api/image/imagename.jpg'} alt='profile' />
folder structure: main directory:
F:\Coursera\React_Flask\SocialNetwork\Frontend\
--api:
-image //images in this folder
-venv
-user_api.py //flask api
--node_modules
--public
--src:
-components
-profile
-profilepage.js //react component.