When I fill and submit pdf form, send_from_directory returns the old file. I use pdftk to push fdf to pdf and flatten, but if I give the same filename as output with the old one, Flask shows the old file. Why isn't it overwritten by the new one? Thanks.
Asked
Active
Viewed 773 times
2 Answers
0
@app.route('/uploads/<filename>')
def show_pdf_form(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
@app.route('/get_data_as_fdf', methods = ['GET', 'POST'])
def get_pdf_data_as_fdf():
# create fdf file
fdf_string = request.data
fdf_file = open(os.path.join(app.config['UPLOAD_FOLDER'], "data.fdf"), "w")
fdf_file.write(fdf_string)
fdf_file.close()
# merge fdf to pdf and flatten pdf
call(["pdftk", "./uploads/send_data_as_fdf.pdf", "fill_form",
"./uploads/data.fdf", "output", "output.pdf", "flatten"])
return redirect(url_for('show_pdf_form', filename = filename))
These are related code snippets. Thank you.

hyhr
- 91
- 1
- 3
0
Flask send_from_directory
uses send_file
internally. send_file
has cache timeout which you can set to 0.
Try clearing the cache and hitting the URL in incognito mode. if it works, you can do:
send_from_directory(app.config['UPLOAD_FOLDER'], filename, cache_timeout=0)
Or you can try any of the options mentioned in: Disabling caching in Flask

Ayush Goyal
- 1
- 1
- 1