I've made a page that allows users to upload a file with HTML input tags:
<p><input type="file" accept="image/*" name="itemimg" id="itemimg" onchange="loadFile(event)" required></p>
The page uses enctype multipart/form-data at the top of the form since it uses a POST request to retrieve a file.
<form action="/sell" method="post" enctype='multipart/form-data'>
The problem is that I am able to add the image to a directory in the folder using requestfiles, but am not able to retrieve the name of the image (for example: "image.jpg") using imgsrc = request.form.get("itemimg") and store into an SQLITE3 database. When using request.form, the system simply retrieves null.
f = request.files['itemimg']
f.save(os.path.join(
app.config['UPLOAD_FOLDER'], secure_filename(f.filename)))
However, when I remove enctype multipart/form-data from the input at the top of my HTML file, I am able to store the name of the file "image.jpg" into the database using request.form but unable to download the file into my directory.
Is there a workaround so that I am able to store the file in the directory AND add it to the database using the request.form?