Post with API: $fileData issue

Hello!
As a beginner, I am testing Omeka S API and I encounter an error:

TypeError: Argument 1 passed to Omeka\Api\Request::setFileData() must be of the type array, null given, called in /var/www/html/omeka-s/application/src/Api/Manager.php on line 77 and defined in /var/www/html/omeka-s/application/src/Api/Request.php:129
Stack trace:
#0 /var/www/html/omeka-s/application/src/Api/Manager.php(77): Omeka\Api\Request->setFileData(NULL)
#1 /var/www/html/omeka-s/application/src/Mvc/Controller/Plugin/Api.php(94): Omeka\Api\Manager->create('items', Array, NULL, Array)
#2 /var/www/html/omeka-s/application/src/Controller/ApiController.php(96): Omeka\Mvc\Controller\Plugin\Api->create('items', Array, NULL)
#3 /var/www/html/omeka-s/application/src/Controller/ApiController.php(181): Omeka\Controller\ApiController->create(Array, NULL)
#4 /var/www/html/omeka-s/vendor/zendframework/zend-mvc/src/Controller/AbstractRestfulController.php(429): Omeka\Controller\ApiController->processPostData(Object(Zend\Http\PhpEnvironment\Request))
#5 /var/www/html/omeka-s/application/src/Controller/ApiController.php(154): Zend\Mvc\Controller\AbstractRestfulController->onDispatch(Object(Zend\Mvc\MvcEvent))
#6 /var/www/html/omeka-s/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Omeka\Controller\ApiController->onDispatch(Object(Zend\Mvc\MvcEvent))
#7 /var/www/html/omeka-s/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#8 /var/www/html/omeka-s/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(105): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#9 /var/www/html/omeka-s/vendor/zendframework/zend-mvc/src/Controller/AbstractRestfulController.php(313): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#10 /var/www/html/omeka-s/vendor/zendframework/zend-mvc/src/DispatchListener.php(119): Zend\Mvc\Controller\AbstractRestfulController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#11 /var/www/html/omeka-s/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#12 /var/www/html/omeka-s/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#13 /var/www/html/omeka-s/vendor/zendframework/zend-mvc/src/Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#14 /var/www/html/omeka-s/index.php(17): Zend\Mvc\Application->run()#15 {main}

If I edit /application/src/Controller/ApiController.php->processPostData() (l 178) like this:

public function processPostData(Request $request)
    {
        $contentType = $request->getHeader('content-type');
        if ($contentType->match('multipart/form-data')) {
            $content = $request->getPost('data');
            $fileData = $request->getFiles()->toArray();
        } else {
            $content = $request->getContent();
//            $fileData = null; //current line
            $fileData = []; //my edit
        }
        $data = json_decode($content, true);
        return $this->create($data, $fileData);
    }

It seems to work well. Is it a bug or I misuse the API?

1 Like

It’s a bug. The request object was significantly refactored recently and had the “array” restriction added for fileData, but this was left unchanged.

The change you’ve made is fine (and of course we’ll fix it as well).

OK, thank you for your answer. :slight_smile:
Do you want I open an issue on GitHub bug tracker?

I went and fixed it already, so there’s no need. An issue would have been perfectly appropriate though.