TYPO3: How to use file upload with extbase

extbasetypo3

I'm building a simple extension based on extbase / fluid which has an
upload form in a frontend plugin. It was working in 6.0.4, but now I get
the following exception when I try to upload a file:

#1297759968: Exception while property mapping at property path "fichier":No converter found which can be used to convert from "array"
to "string".

The problem seems to be related to the fact that the web request
receives an array for the uploaded file, but the model stores it as a
string. How can I get rid of this exception? How should I handle file
upload in extbase?


The extension was started using Extension Builder. fichier is a string property in the Model, containing the name of the uploaded file (located into uploads/tx_myext/). The template for the plugin contains an upload field build from a form.upload ViewHelper. On TYPO3 6.0.4, when I submit the form, I receive an object as argument to the createAction function. From that object, I call getFichier that returns me the file array of the uploaded file. Then, I can extract the original file name, copy the temp file to the right location, and set the value of the fichier property using the original file name.

Now, in TYPO3 6.1.0, I get the above exception before entering the createAction function. My guest is that PropertyMapper is trying to translate the file array to a string to match the type of fichier property.

What I don't know is was the way it worked before was a bug, or is it the way it works now that is the bug. And if it really works the way it is intended to do, how should I be able to handle file upload in an extbase extension?

Best Solution

 /**
 * initialize actions
 */
public function initializeAction() {
    if ($this->arguments->hasArgument('myModel')) {
        $this->arguments->getArgument('myModel')->getPropertyMappingConfiguration()->setTargetTypeForSubProperty('upload', 'array');
    }
}

http://www.typo3lexikon.de/typo3-tutorials/extensions/extbase/property-mapper.html

Related Question