Problem/Motivation

Not sure if this is by design or configurable, but when importing files from a rest export files are never moved from temp to public storage (as per the default behavior when creating such entities from the UI).

Proposed resolution

Remaining tasks

User interface changes

API changes

Comments

Wim Leers’s picture

Title: Deserialized and saved file entities never make it out of temporary:// storage. » Deserialized and saved file entities never make it out of temporary:// storage
Status: Active » Closed (works as designed)

From \Drupal\hal\Normalizer\FileEntityNormalizer::denormalize():

  public function denormalize($data, $class, $format = NULL, array $context = array()) {
    $file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody();

    $path = 'temporary://' . drupal_basename($data['uri'][0]['value']);
    $data['uri'] = file_unmanaged_save_data($file_data, $path);

    return $this->entityManager->getStorage('file')->create($data);
  }

i.e. it's up to the recipient of denormalize() to call save(), which would move it from temporary:// to public://.

This is exactly in line with what \Drupal\hal\Normalizer\ContentEntityNormalizer::denormalize() does:

public function denormalize($data, $class, $format = NULL, array $context = array()) {
    …

    $entity = $this->entityManager->getStorage($typed_data_ids['entity_type'])->create($values);

    …

    return $entity;
  }