public function putToNode(
    NodeInterface $node,
    MediaTypeInterface $media_type,
    TermInterface $taxonomy_term,
    Request $request
  ) {
    $content_type = $request->headers->get('Content-Type', "");

    if (empty($content_type)) {
      throw new BadRequestHttpException("Missing Content-Type header");
    }

    $content_location = $request->headers->get('Content-Location', "");

    // Since we create both a Media and its File,
    // start a transaction.
    $transaction = $this->database->startTransaction();

    try {
      $media = $this->service->putToNode(
        $node,
        $media_type,
        $taxonomy_term,
        $request->getContent(TRUE),
        $content_type,
        $content_location
      );

      // We return the media if it was newly created.
      if ($media) {
        $response = new Response("", 201);
        $response->headers->set("Location", $media->url('canonical', ['absolute' => TRUE]));
      }
      else {
        $response = new Response("", 204);
      }
      return $response;
    }
    catch (HttpException $e) {
      $transaction->rollBack();
      throw $e;
    }
    catch (\Exception $e) {
      $transaction->rollBack();
      throw new HttpException(500, $e->getMessage());
    }
  }