Search code examples
javascriptfat-free-frameworkaxios

Fat Free failed to catch Axios FormData with file upload


I use Axios to do AJAX request to Fat Free.

Here's the reciever code:

$files = \Web::instance()->receive(function($file){
    var_dump($file);
    return (substr($file["type"],0,6)=="image/");
}, true);
if($files===false)
    throw new \Exception\UnexpectedInput("U didn't provide any file");

and here's the sender (currently i use Axios to do the job.)

return new Promise((ok,err)=>{
    var datanya = new FormData();
    datanya.append(this.generateRandomString(), new Blob([file[0]], {type:"image/jpeg"}), "image.jpg");
    // generate id for cancelation.
    this.uploadCancelSource = CancelToken.source();
    var config = {
        cancelToken: this.uploadCancelSource.token,
        onUploadProgress:(e)=>{
            this.uploadProgress = Math.round( (e.loaded * 100) / e.total );
        }
    }
    APICall.put("invoice/bukti", datanya, config).then(e=>{
    });
});

The payload seems to be ok for me, i mean, it transmits filename, content type, and form name. But FatFree Web's Class didn't catch it. It just telling that it is a application/octet-stream.

Here's screenshoot for the payload

Request Dumping SS

And here's the dumped data from the \Web::instance()->receive

Dumped data from server

You know the problem?


Solution

  • the current behavior of class Web are the main problem. As you can see at the source code, or see the documentation, it has different behaviour on different request method.

    A little hacking, can be used to fix the current problem, but i decided to change the request method.