Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to handle url-encoded and form-data request #685

Open
ItzfeminisceBEnd opened this issue Oct 20, 2023 · 2 comments
Open

Unable to handle url-encoded and form-data request #685

ItzfeminisceBEnd opened this issue Oct 20, 2023 · 2 comments

Comments

@ItzfeminisceBEnd
Copy link

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?

@DeveloperMarius
Copy link
Contributor

Hey,

can you share your request body and headers with us?

~ Marius

@ItzfeminisceBEnd
Copy link
Author

ItzfeminisceBEnd commented Oct 24, 2023

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()]);
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants