Good example for image uploads

Hello all,

very simple scenario: the frontend user can upload his image himself.

My previous implementation only worked because I added the property “picture” to the model “FrontendUser”, which is of type “FileReference”.

BUT the FrontendUser already has a picture: The property “image”. But this is (for whatever reason) of type “ObjectStorage<FileReference>” with a maximum number of 1.

:?

Now to my question: In the docu there is a reference to an example - does it all have to be so complicated?

What you need everything apparently:

  • an own version of the model "FileReference
  • an own ObjectStorage-Converter
  • an own FileReference converter
  • and an own Update-View-Helper

In the sample controller I also find the lines:

 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Container::class)
        ->registerImplementation(
            \TYPO3\CMS\Extbase\Domain\Model\FileReference::class,
            \Helhum\UploadExample\Domain\Model\FileReference::class
            );

where the “container” class is marked as deprecated. :?

I can’t figure out from the deprecated annotation either, unfortunately:
Use symfony DI and GeneralUtility::makeInstance() instead.

What is symfony DI ?
And does this DI then also provide “registerImplementation()” ? Is this some kind of class replacement ? And is that a good example then ?

Is uploading files so unusual that it doesn’t need more attention or does it have to be so individual every time?

All my questions are quite serious and polite. If they come across as “trollish”: I didn’t mean there… I would rather like to understand the background better.

Greetings
Clemens

PS: I am already looking forward to the LTS 12 version. There is apparently a TCA directory selector… so you can, then specify the destination of the upload files better. :slight_smile:

Translated with www.DeepL.com/Translator (free version)


Hallo zusammen,

ganz einfaches Szenario: Der Frontend-Nutzer kann sein Bild selber hochladen.

Meine bisherige Implementierung hat nur funktioniert, weil ich das Model “FrontendUser” um die Eigenschaft “picture” ergänzt hatte, welches vom Typ “FileReference” ist.

ABER der FrontendUser hat ja bereits ein Bild: Die Eigenschaft “image”. Diese ist aber (warum auch immer) vom Typ “ObjectStorage” mit einer maximalen Anzahl von 1.

:?

Nun zu meiner Frage: In der Doku wird auf ein Beispiel verwiesen - muss das alles so kompliziert sein?

Was man alles scheinbar braucht:

  • eine eigene Version des Model “FileReference”
  • einen eigenen ObjectStorage-Converter
  • einen eigenen FileReference-Converter
  • und einen eigenen Update-View-Helper

Im Beispiel-Controller finde ich auch die Zeilen:
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Container::class)
->registerImplementation(
\TYPO3\CMS\Extbase\Domain\Model\FileReference::class,
\Helhum\UploadExample\Domain\Model\FileReference::class
);
wobei die Klasse “Container” als deprecated markiert ist. :?

Aus der deprecated-Anmerkung werde ich leider auch nicht schlau:
“Use symfony DI and GeneralUtility::makeInstance() instead.”

Was ist symfony DI ?
Und bietet dieses DI dann auch “registerImplementation” ? Ist das so eine Art Klassen Replacement? Und ist dass dann ein gutes Beispiel?

Ist das Hochladen von Dateien so ungewöhnlich, dass es keiner größeren Aufmerksamkeit bedarf oder muss das jedes mal so individuell sein?

All meine Fragen sind ganz ernst und höflich gemeint. Wenn diese “Trollig” rüberkommen: Da wollte ich nicht… ich möchte eher den Hintergrund besser verstehen.

Grüße
Clemens

PS: ich freue mich ja schon auf die LTS 12er Version. Da gibt es scheinbar einen TCA-Verzeichnis-Selektor… damit kann man, dann des Zielort der Upload-Files besser spezifizieren. :slight_smile:

Hey Clemens,

the extension femanager does some image upload for fe_users. Maybe you can either use this extension or take a look how it works there.

=> TYPO3 Extension 'femanager' (femanager)

Thanks for the tip…

Unfortunately the extension “femanager” is not available for Typo3 11.5. So have analyzed the extension theoretically.

yes - in femanager you can upload images to user.

But in feManager I didn’t find any TypeConverter. Much worse: if I interpret it correctly, the image upload is realized via Ajax.

Unfortunately this is not a simple solution how to implement a simple file upload. (and that’s what I was actually looking for)

My current solution approach works with a “virtual*”. model attribute:

I extend the model with an additional attribute, e.g. “imageUpload”. This is from the type array. Then the controller can evaluate the new attribute and store (or replace) the new image in the actual image attribute (of type ObjectStorage).

This is not pretty, but IMHO currently the solution that will still be comprehensible in a few months. Instead of “magic” TypeConverters that somehow do their day job and where possible exceptions are mostly hard to interpret.

Thanks for your help…

*) with virtual I mean that this attribute is not mapped to any database column. So it is not stored, but only used for the transport from the controller to the view and back.

Translated with www.DeepL.com/Translator (free version)

Hi,

You can do normal file upload as done in PHP and it will become available in fileadmin
check the code of pluploadfe extension