importResourceFromContent() public method

The given content typically is binary data or a text format. On a successful import this method returns a PersistentResource object representing the imported content and automatically publishes it to the configured publication target. The specified filename will be used when presenting the resource to a user. Its file extension is important because the resource management will derive the IANA Media Type from it.
public importResourceFromContent ( string $content, string $filename, string $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, string $forcedPersistenceObjectIdentifier = null ) : PersistentResource
$content string The binary content to import
$filename string The filename to use for the newly generated resource
$collectionName string Name of the collection this new resource should be added to. By default the standard collection for persistent resources is used.
$forcedPersistenceObjectIdentifier string INTERNAL: Force the object identifier for this resource to the given UUID
return PersistentResource A resource object representing the imported resource
 /**
  * @return Asset
  * @throws \Neos\Flow\ResourceManagement\Exception
  */
 protected function buildAssetObject()
 {
     $resource = $this->resourceManager->importResourceFromContent('Test', 'test.txt');
     $asset = new Asset($resource);
     $this->assetRepository->add($asset);
     return $asset;
 }
 /**
  * @test
  */
 public function fileGetContentsReturnFixtureContentForResourceUri()
 {
     $resource = $this->resourceManager->importResourceFromContent('fixture', 'fixture.txt');
     $this->assertEquals('fixture', file_get_contents('resource://' . $resource->getSha1()));
 }
 /**
  * @param array $source
  * @param PropertyMappingConfigurationInterface $configuration
  * @return PersistentResource|FlowError
  * @throws InvalidPropertyMappingConfigurationException
  */
 protected function handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = null)
 {
     $hash = null;
     $resource = false;
     $givenResourceIdentity = null;
     if (isset($source['__identity'])) {
         $givenResourceIdentity = $source['__identity'];
         unset($source['__identity']);
         $resource = $this->resourceRepository->findByIdentifier($givenResourceIdentity);
         if ($resource instanceof PersistentResource) {
             return $resource;
         }
         if ($configuration->getConfigurationValue(ResourceTypeConverter::class, self::CONFIGURATION_IDENTITY_CREATION_ALLOWED) !== true) {
             throw new InvalidPropertyMappingConfigurationException('Creation of resource objects with identity not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_IDENTITY_CREATION_ALLOWED" to TRUE');
         }
     }
     if (isset($source['hash']) && preg_match('/[0-9a-f]{40}/', $source['hash'])) {
         $hash = $source['hash'];
     }
     if ($hash !== null && count($source) === 1) {
         $resource = $this->resourceManager->getResourceBySha1($hash);
     }
     if ($resource === null) {
         $collectionName = $this->getCollectionName($source, $configuration);
         if (isset($source['data'])) {
             $resource = $this->resourceManager->importResourceFromContent($source['data'], $source['filename'], $collectionName, $givenResourceIdentity);
         } elseif ($hash !== null) {
             /** @var PersistentResource $resource */
             $resource = $this->resourceManager->importResource($configuration->getConfigurationValue(ResourceTypeConverter::class, self::CONFIGURATION_RESOURCE_LOAD_PATH) . '/' . $hash, $collectionName, $givenResourceIdentity);
             if (is_array($source) && isset($source['filename'])) {
                 $resource->setFilename($source['filename']);
             }
         }
     }
     if ($resource instanceof PersistentResource) {
         return $resource;
     } else {
         return new FlowError('The resource manager could not create a PersistentResource instance.', 1404312901);
     }
 }