I am working on a plugin which adds a custom field type.
The field type should allow the upload of a file, which is then sent to another server (thus not a normal asset, as it is only temporarily stored on the server). My goal is to save the file and store the path and some metadata as JSON in field type column.
I have made a plugin with a custom field type which works when I am using a text input field.
But changing the type to a file upload does nothing.
I've seen the following solution on SE: https://craftcms.stackexchange.com/a/28253/11621 but the UploadedFile Class always returns "null".
public function serializeValue($value, ElementInterface $element = null)
{
$namespace = $element? $element->getFieldParamNamespace() . '.' : '';
$fullhandle = $namespace.$this->handle;
$file = UploadedFile::getInstanceByName($fullhandle);
dd($file);
}
The variable $fullhandle
contains the value fields.introductionVideo
which matches the form input's name of fields[introductionVideo]
.
The form has the attribute for file uploads enctype="multipart/form-data"
for file uploads.
Does anybody have a clue what might be wrong or where to find more information/working example about how to do it correctly?