simple-php-router icon indicating copy to clipboard operation
simple-php-router copied to clipboard

Unable to handle url-encoded and form-data request

Open ItzfeminisceBEnd opened this issue 2 years ago • 2 comments

The input()->() and request()-> will not catch file contents in request.

I have tried every possible means to handle uploaded files but it's not present in the request body.

I set content type to application/json, it won't. I also set it to url-encoded, even form-data. Neither was it able to handle.

Please is there some other way to get these content?

ItzfeminisceBEnd avatar Oct 20 '23 05:10 ItzfeminisceBEnd

Hey,

can you share your request body and headers with us?

~ Marius

DeveloperMarius avatar Oct 24 '23 10:10 DeveloperMarius

Request Header: Authorization: Bearer <token> User-Agent: PostmanRuntime/7.34.0 Accept: / Cache-Control: no-cache Postman-Token: 5c0fe45e-0db4-44dd-b83b-0250c95fe87f Host: localhost Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Type: multipart/form-data; boundary=--------------------------191050165857157560352247 Cookie: PHPSESSID=hhgbb05m0eklch792b435rjutt Content-Length: 19554622

Request Body: post_text: "Hello world" post_img: <file>

MY CODE:

public function store() {
    try {
      $validate = purify(input()->all());
      $req = $validate([
        "post_text" => 'required',
        "post_img" => 'optional',
      ]);
      //input()->file('post_img') // Always null
      // $req->post_text == input()->find("post_text)
      // $req->post_img == input()->file(post-img) // Butt this is always null
      return Post::getInstance()->store($req->post_text, input()->file("post_img", null));
    }catch(\Exception $e) {
      Logger::system($e->getMessage());
      return json_response(["message" => $e->getMessage()]);
    }
  }

ItzfeminisceBEnd avatar Oct 24 '23 11:10 ItzfeminisceBEnd