Which Drupal 8.1.x Rest API property in the JSON request controls Drupal's File status (Temporary and Permanent) logic?

537 views Asked by At

Which Drupal Rest API property in the JSON request controls Drupal's File status (Temporary and Permanent) logic?

I am trying to upload via Multipart/form-data (i.e. JSON data plus attached [uploaded] file) to Drupal 8.1.x CMS. So far, the upload is successful. However, In Drupal uploaded files (via REST) are initially stored by default with "TEMPORARY" status.

I want to tell Drupal to set the status of the file to "PERMANENT" when it stores my file into the Drupal CMS. I did some searching and found out that the keyword "status" in File.php did the magic around TEMPORARY and PERMANENT. So far, I have been including the property "status" in my Json request but Drupal generates an Internal error --> message:

"Access denied on creating field 'status'"

after having set "status": [{"value": "1"}]

BTW: I have tried different variations on the value representation of "value", that is "1", 1, true, "true", ..., since I was not able to get more information about the API specification specific to the Rest File upload interface.

I have searched Drupal site for a solution but with no satisfying results yet.

Question: Does anyone know how to construct the JSON request with status PERMANENT?

1

There are 1 answers

1
Paul Sweatte On

This is a bug, which can be fixed in the following Drupal source file:

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;
   }
 }

References