1

I'm retrieving a POSTed file with:

$this->app->post(Extension::API_PREFIX . "profile/picture", array($this, 'post_profile_pic'))
      ->bind('post_profile_pic');

public function post_profile_pic(Request $request) {
    $response = $this->app->json(array(
        'file' => $request
    ));
    return $response;
}

I'm using Postman to upload the file (see screenshot), but the request is empty:

{
    "file": {
        "attributes": { },
        "request": { },
        "query": { },
        "server": { },
        "files": { },
        "cookies": { },
        "headers": { }
    }
}

Yet it obviously knows that there should be a file there. So how do I access the file?

babbaggeii
  • 7,577
  • 20
  • 64
  • 118
  • It may simply not be serializable (IIRC UploadedFile is like that). What happens if you do `$request->files->count()`? – Maerlyn Jan 12 '15 at 18:55

1 Answers1

3

Uploaded files in PHP are not sent with $_POST but in a separate variable called $_FILES ( http://php.net/manual/en/features.file-upload.post-method.php ) - so in your case you should take a look at

$this->app->files

If you use the default form components from symfony the documentation is at http://symfony.com/doc/current/reference/forms/types/file.html#basic-usage

In the simpleforms module files are retrieved by the lines following

$files = $this->app['request']->files->get($form->getName());

Which is using the basic structure that the Bolt, Silex and Symfony components provide. (See also https://github.com/jadwigo/SimpleForms/blob/master/Extension.php#L505)

jadwigo
  • 339
  • 1
  • 9