We have a content-type w/ a File field. We would like to PATCH a node of that type to update only the File field with a newly uploaded file.
We've been able to figure out how to successfully POST a new file to the server, so now we only need to update the node to point to the file (that is already on the server now). It seems we should use a PATCH on the node, passing in just the data pertaining to the File field with the updated path to the file -- but no matter how we try, we always get back errors (usually 400).
It seems likely that we're just not formatting the data in the request right. What is the proper format for patching a node to update a File field? Or is this an unsupported feature?
Thanks for any help you can provide!
Comments
Comment #2
grimreaperHello,
Did you use the JSONAPI file module? I got the following similar (same?) problem. Please see #2897545: Support PATCH operation
Comment #3
cmoesel commentedI don't think the problem described in #2897545 is the same, but it's possible that they share a root cause.
The main difference is that #2897545 seems to be trying to PATCH the file entity itself. We, however, are trying to PATCH a node that has a File field -- so we're not PATCHING a file entity, but rather, we're trying to associate a new file entity (which we already created via POST) to a File field on an existing node. We can't seem to figure out how to PATCH the node to reference the file entity.
Comment #4
cmoesel commentedIs anyone able to confirm or deny if this is even intended to work (or known to work under any circumstances)?
Comment #5
wim leersReally? 😲
How?
Because neither Drupal core's REST module nor JSON API supports that today. For Drupal core's REST module, we have #1927648: Allow creation of file entities from binary data via REST requests. And JSON API is effectively blocked on that issue to support it.
Comment #6
wim leersOh … you're able to POST a file by using https://www.drupal.org/project/jsonapi_file, which is a work-around until #1927648: Allow creation of file entities from binary data via REST requests happens.
If you could write a failing test, that'd be super helpful. Do something like:
It'd be good to have explicit test coverage for this common use case anyway.
Comment #7
wim leersAny chance you're using a
private://file?If so, this is a duplicate of #2897257: Add test coverage to ensure it's possible to reference File entities.
Comment #8
wim leersComment #9
wim leersThis is definitely a duplicate of #2897257: Add test coverage to ensure it's possible to reference File entities.
Comment #10
wim leers