Cant upload an image to a new model object

Issue #21 resolved
Stefan Kruse created an issue

Hi,
i try to create model object with an uploaded image. But i dont get it working.
The model is created but no file reference.
Could someone give me an example? I try example form doc but this dont work.

I found out that in der Fal::createForModel function “model->getUid()” is always null. so no relation could be created.
Is this right?

$fal = $this->fromFile([
            'src'           => $filePath,
            'title'         => $itemData['title'] ?? null,
            'description'   => $itemData['description'] ?? null,
            'link'          => $itemData['link'] ?? '',
            'crop'          => $itemData['crop'] ?? '',
            'sorting'       => $itemData['sorting'] ?? $sorting,
            'pid'           => $model->getPid(),
            'uid'           => $model->getUid(),
            'table'         => $table,
            'field'         => $field,
            'cruser_id'     => $cruser_id,
        ]);

I use T3 V11.

Comments (8)

  1. Stefan Kruse reporter

    I think the problem is that the model was not persisted before adding the file reference.

  2. Stefan Kruse reporter

    Hi David. Yes i have but i dont get it to work. Without files everything is fine, but even i try to upload a file the entry and the file was created in database but without file relation. The file relation entry in db is still missing. any ideas what i can do ? Thanks a lot

  3. Stefan Kruse reporter

    Here is the error message:

    An exception occurred while executing 'INSERT INTO `sys_file_reference` (`fieldname`, `tablenames`, `table_local`, `uid_local`, `uid_foreign`, `sorting_foreign`, `pid`, `description`, `title`, `link`, `crop`, `tstamp`, `crdate`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["files", "tx_apidemo_domain_model_entry", "sys_file", 95, "", 1666592703, 4, null, null, "", "", 1666592703, 1666592703]: Incorrect integer value: '' for column `db`.`sys_file_reference`.`uid_foreign` at row 1
    

    And it comes from the Fal::createForModel Method. Where the FAL reference should be created.

    'pid' => $model->getPid(),
    'uid' => $model->getUid(),

    \$model->getUid() is null. 😌

  4. Stefan Kruse reporter

    i could not believe that this ha ever worked.

    In the function toModel the model is never persisted. And therefore in next functions like Fal::createForModel the model has no id, because its not persisted.

    You already have a @todo in the toModel function.

    public function toModel( $className = null, $parentModel = null ) {
    
            $arr = $this->initialArgument;
    
            $model = \nn\t3::injectClass( $className );
            var_dump($arr);die;
            return \nn\t3::Obj($model)->merge( $arr );
    
            # ToDo: Prüfen, warum das nicht funktioniert. Model wird nicht persistiert!
            # $dataMapper = \nn\t3::injectClass(DataMapper::class);
            # return $dataMapper->map($model, [$arr]);
        }
    

  5. David Bascom

    We have been using this for years. The todo is meant as a question, because the TYPO3 recommended way of doing things doesn’t work. 

    I currently suspect it has to do with the strict mode in the DB settings. We‘ll try to reproduce this.

    What DB are you using?

  6. Stefan Kruse reporter

    Hi, thanks for reply.

    I use it in ddev and my config looks like:

    database:

    type: mariadb

    version: "10.3"

  7. David Bascom

    Closed because we could not reproduce it. Feel free to open it again, if the problem persists in other projects.

  8. Log in to comment