artyom-beilis / cppcms

CppCMS Framework
Other
450 stars 111 forks source link

request().files() in Input content filtering #91

Open masaoliou opened 2 years ago

masaoliou commented 2 years ago

client:

let fd=new FormData();
fd.append('name','myname');
fd.append('image',e.target.files[0]);
fetch('/upload',{method:'POST',body:fd});

server:

!request().files().empty() used to return true within the block if(!request().is_ready()). Recently it started to return true within the block if(request().is_ready()).

Exactly where should the check if(!request().files().empty()) be done?

Thank you in advance!

class my_upload: public cppcms::application {
public:
void main(std::string path) {
    if(!request().is_ready()) {
        session().load();
        if(!request().files().empty()){ //Used to be true
            request().files()[0]->set_temporary_directory("/tmp/uploads");
            request().files()[0]->set_memory_limit(512);
        }
    }
    else {
        if(!request().files().empty()){ //Is true now.
            request().files()[0]->set_temporary_directory("/tmp/uploads");
            request().files()[0]->set_memory_limit(512);
        }
        release_context()->submit_to_pool();
    }
};