0

I'm using php_curl to POST a binary image to my local D8.8 app but it keeps returning a 500 error:

The "entity:file:undefined" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: helpful list of D8 entities.

Using the example "Flow 1" from this doc page, I started out with this:

     $binary = file_get_contents('Wilson.jpeg');
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,'http://localhost/jsonapi/node/doctor/field_photo');
      curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($ch, CURLOPT_USERPWD, "admin:mypwd");
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_VERBOSE, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $binary);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/octet-stream',
        'Accept: application/vnd.api+json',
        'Content-Disposition: file; filename="Wilson.jpeg"',
        ));
      curl_setopt($ch, CURLOPT_POSTFIELDS, $binary);
      $result = curl_exec($ch);

Searching I read that D8 is more strict about entity bundles, I can report that my field_photo for the doctor content type is instantiated as an image. Examining my app's /admin/structure/file-types/manage/image/edit I can see in the Known Mime Types section that application/octet-stream and image/jpeg exists and standing by. Rereading the error Drupal seems to perceive that this is a file but isn't clear what kind it is. I thought I was being clever and changed the Content Disposition from 'file' to 'image' but no such luck. Exact same error returned. Swapping it out to one of the suggested to 'entity:file:image' did not change the error message. It suggests to me that I need to do something in this curl header to prompt Drupal to understand that this is a file that has a plugin established for it.

Digging into the stacktrace I see that it's generating "entity:file:undefined" because the Bundle property for this entity is "undefined". Working backwards, in context of the doctor node definition, the field passes through the MimeTypeGuesser class has figured out that it is a jpeg and its attributes. But this gets lost when passed to the TemporaryJsonapiFileFieldUploader where it attempts to validate the File.

I've attempted adding "application/octet-stream" as a second entry underneath the "image/*" on the /admin/structure/file-types/manage/image/edit page but nothing changes. How should I associate its bundle to "image" so that I end up with "entity:file:image" and I can move on?

One thing that bothers me is that file uploading was added to the 8x-2.x branch and I'm reading that it is part of core. I'm on 8.8.5 and am assuming I have the latest after running composer update. I've checked some of the file diffs on jttps://git.drupalcode.org/project/jsonapi/ and it appears the files I'm working on are current, but it bothers me that I haven't resolved this. The json output from this module returns "jsonapi":{"version":"1.0" which is an indicator of the external jsonapi specification, not the drupal module.

0

1 Answer 1

0

The usual troubleshooting step when it seems to work for others is to spin up a minimal D8 app and see if it occurs there. The minimal app worked as expected, which points to a module conflict. For me, the contrib module file_entity was causing this trouble. It took several efforts to get it uninstalled, and only by following the #8 comment on https://www.drupal.org/project/file_entity/issues/3060204 where I try to install it would I be able to finally uninstall it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.