Send_from_directory() doesn't function

I’m using send_from_directory function in flask. The code below perfectly works if I use absolute path to the local file but when it is deployed it returns 404.

@users.route("/<string:session_token>/<path:filename>", methods=['GET', 'POST'])
@login_required
def download_pdf(session_token, filename):
    user = User.query.filter_by(session_token=session_token).first()
    try:
        full_path = os.path.join("files/static/data/", user.customer_number)
        return send_from_directory(full_path, filename)
    except Exception:
        abort(404)

link in HTML to download the file:
<a href="{{ url_for('users.download_pdf', session_token=user.session_token, filename=po) }}" target="_blank">{{ po }}</a>

Hi,

There will always be differences between environments: development mode/Local, production mode/Render, OS, versions, resources, etc. These differences need to be considered and configured as required for your own app in each environment.

Render instances have an ephemeral filesystem, meaning any file written to the instance after it has booted will be lost when it next restarts (e.g. spun down if on free instance type, next deploy, manual restart, etc.).

If the files in question are generated/saved to the instance, they’ll be lost on each deploy, so you would need to save them to a persistent store, e.g., a Render Disk (which is chargeable and also requires a paid instance type) or an external service like AWS S3.