What property of the Drupal 8.1.x Rest API in a JSON request controls the Drupal File status logic (Temporary and Permanent)?

What property of the Drupal Rest API in a JSON request controls the state logic of the Drupal file (temporary and permanent)?

I am trying to upload via Multipart / form-data strong> (ie JSON data plus the attached [uploaded] file) to the Drupal 8.1.x CMS. So far, the download has been successful. However, in Drupal, downloaded files (via REST) ​​are initially stored by default with the status "TEMPORARY".

I want to tell Drupal to set the file status to "PERMANENT" when it stores my file in Drupal CMS. I did some searching and found out that the β€œstatus” keyword in File.php did the magic around TEMPORARY and PERMANENT. So far, I have included the "status" property in my Json request, but Drupal generates an Internal error β†’ message:

"Access denied on creating field 'status'"

after setting "status": [{"value": "1"}]

BTW: I tried different options for representing the values ​​"value", that is, "1", 1, "true", "true", ..., since I could not get more information about the API specification regarding the Rest file upload interface .

I searched the Drupal site for a solution, but have not yet received satisfactory results.

: - , JSON PERMANENT?

+4
1

, ​​ Drupal:

diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php
index cdb1df0..3237905 100644
--- a/src/Normalizer/FileEntityNormalizer.php
+++ b/src/Normalizer/FileEntityNormalizer.php
@@ -52,6 +52,7 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
     else {
       throw new \RuntimeException(SafeMarkup::format('Failed to write @filename.', array('@filename' => $entity->getFilename())));
     }
+    $entity->status = FILE_STATUS_PERMANENT;
     return $entity;
   }
 }

+3

Source: https://habr.com/ru/post/1650661/


All Articles