handleFileUploadForField example


  public function handleFileUploadForExistingResource(Request $request, ResourceType $resource_type$file_field_name, FieldableEntityInterface $entity) {
    $file_field_name = $resource_type->getInternalName($file_field_name);
    $field_definition = $this->validateAndLoadFieldDefinition($resource_type->getEntityTypeId()$resource_type->getBundle()$file_field_name);

    static::ensureFileUploadAccess($this->currentUser, $field_definition$entity);

    $filename = $this->fileUploader->validateAndParseContentDispositionHeader($request);
    $file = $this->fileUploader->handleFileUploadForField($field_definition$filename$this->currentUser);

    if ($file instanceof EntityConstraintViolationListInterface) {
      $violations = $file;
      $message = "Unprocessable Entity: file validation failed.\n";
      $message .= implode("\n", array_map(function DConstraintViolationInterface $violation) {
        return PlainTextOutput::renderFromHtml($violation->getMessage());
      }(array) $violations->getIterator()));
      throw new UnprocessableEntityHttpException($message);
    }

    if ($resource_type->getFieldByInternalName($file_field_name)->hasOne()) {
      
Home | Imprint | This part of the site doesn't use cookies.