Skip to content

Tips: read a posted file

Andrea Fontana edited this page Aug 23, 2023 · 2 revisions

If file is posted inside request body:

auto file_content = request.body;

If file is posted using a form:

assert(request.form("form_field_name").isFile == true);

// This file will be deleted soon, copy or move this file if you want to keep it.
auto file_path = request.form.read("form_field_name").path;     // Ex: /tmp/serverino_upload_23424243243_213123
auto file_name = request.form.read("form_field_name").filename; // Ex: test.zip