How do I add a private file to node's file field from Base64 in code I'm struggling to add file to node in code. I know about File::create() but I want to add file to node based on field configuration of the file field on that particular node's content type, and file's data comes as Base64, not URL or form post.

How do you do it? I'm asking as I want to add file via custom REST call as Base64. 

I am using the following code.

$node = Node::load($data['case_id']);
$files = $node-&gt;field_file;  // unlimited files
/* @var $df \Drupal\field\Entity\FieldConfig */
$df = $node-&gt;getFieldDefinition('field_file'); // ??? can i get this config for saving new file?
$file =  file_save_data(base64_decode($data['data']), ??path??);
$files-&gt;appendItem($file)-&gt;validate();
$node-&gt;save();


Am I on the valid course? I have no clue how to set config from $df and before save. How do I use the configuration of that file field during save? 

Yurii
my final solution was next:

$node = Node::load($data['case_id']);
$files = $node-&gt;field_case_file;
$dfSettings = $files-&gt;getDataDefinition()-&gt;getSettings();
$destination = $dfSettings['uri_scheme'].'://'.$dfSettings['file_directory'].'/'.$filename;
$destination = \Drupal::token()-&gt;replace($destination);
$file = file_save_data(base64_decode($fileData), $destination, FILE_EXISTS_RENAME);

$violations = $files-&gt;appendItem($file)-&gt;validate();

if(count($violations)) {
//throw error
}

$node-&gt;save();