fabarea / media_upload

(Mass) upload Media on the Frontend - TYPO3 CMS extension
Other
19 stars 23 forks source link

Two Upload-Fields in one form #19

Closed freeATweb closed 7 years ago

freeATweb commented 7 years ago

Hi,

if I use one media_upload field in a form, it works perfect.

Now I tried to use a second field (previewimage and image), but without success. None of the image-upload-fields work - both return an empty array.

Both fields have the same Configuration (Domain Model, TCA, sql, ...)

Here's the code:


// get file storate from typoscript settings
    $fileStorage = (int)$this->settings['fileStorageID'];

    /** @var array $uploadedFiles */
    $uploadedFiles = $this->uploadFileService->getUploadedFiles('images');
    $previewImage = $this->uploadFileService->getUploadedFiles('previewimage');

    // Bildergalerie Process uploaded files and move them into a Resource Storage (FAL)
    foreach($uploadedFiles as $uploadedFile) {
                /** @var \Fab\MediaUpload\UploadedFile $uploadedFile */
                $uploadedFile->getTemporaryFileNameAndPath();

        $storage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($fileStorage);

        /** @var File $file */
        $file = $storage->addFile(
            $uploadedFile->getTemporaryFileNameAndPath(),
            $storage->getRootLevelFolder(),
            $uploadedFile->getFileName(),
            'changeName'
        );
                // Create File Reference
        $newFileReference = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\MyExt\\Domain\\Model\\FileReference');
        $newFileReference->setOriginalResource($file);
                $newEntry->addImages($newFileReference);
        }

    // Preview Image: Process uploaded files and move them into a Resource Storage (FAL)

    foreach($previewImage as $uploadedFile) {
                /** @var \Fab\MediaUpload\UploadedFile $uploadedFile */
                $uploadedFile->getTemporaryFileNameAndPath();

        $storage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($fileStorage);

        /** @var File $file */
        $file = $storage->addFile(
            $uploadedFile->getTemporaryFileNameAndPath(),
            $storage->getRootLevelFolder(),
            $uploadedFile->getFileName(),
            'changeName'
        );
                // Create File Reference
        $newFileReference = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\MyExt\\Domain\\Model\\FileReference');
        $newFileReference->setOriginalResource($file);
                $newEntry->addPreviewimage($newFileReference);
        }

Can someone please help me out :-)

Thanks

markuskappe commented 7 years ago

I just fixed this, please see my current pull request.

freeATweb commented 7 years ago

Thank you - works perfect :-)