Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload in REST API
  • Hello,

    I'm coding a REST API. In a PUT method, I want to edit the users resource. But I've a problem with the picture of the user :


    public function put_edit($id = null)
    {

            if (is_null($id) || ! $user = Model_User::find($id))
            {
                    return $this->response('User not found.'), 404);
            }

            $val = Model_User::validate('edit');
                
            if ($val->run(Input::put()))
            {

                    //Picture
                    if (!empty($_FILES))
                    {  
                            //Do something...
                    }
            }
    }


    But it never enter in my "if (!empty($_FILES))" , while in my method post_create, this condition works fine.

    I don't understand, I use the Chrome extension named "Postman" to test my rest queries.

    Thank you in advance for your help !
  • Another clarification : in my form (in Postman), when I add only 1 field (username), Input::put() (in my FuelPHP application) contain this : 

    {"------WebKitFormBoundaryzjdhryRyh5SWbVbB\r\nContent-Disposition:_form-data;_name":"\u0022username\u0022\r\n\r\nmyusername\r\n------WebKitFormBoundaryzjdhryRyh5SWbVbB--\r\n"}


    Normally, I should have :
    {
        "username": "myusername"
    }

    Here the HTTP request en entire :

    PUT /myproject/api/users/edit/36 HTTP/1.1
    Host: localhost
    Cache-Control: no-cache

    ----WebKitFormBoundaryE19zNvXGzXaLvS5C
    Content-Disposition: form-data; name="username"

    myusername
    ----WebKitFormBoundaryE19zNvXGzXaLvS5C


    I precise that I've checked "form-data" option in Postman to send data in my request. If I check "x-www-form-encoded' option, it works, but I can't send files whith this option, it's posible only with "form-data".
  • HarroHarro
    Accepted Answer
    That is afaik currently not supported. You can add a feature request at https://github.com/fuel/core/issues with this use-case.
  • Ok, 

    If I use a POST request it works, but for edit my resource is wrong, no ?
  • HarroHarro
    Accepted Answer
    If you use POST, then PHP will do the decoding of the input. For others, the framework has to to it, and currently it does only support www-form-urlencoded, and no multipart-data (which is quite complex to parse).
  • Ok, than you very much for your help :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion