Hello,

Running Drupal 8.1.2 and have followed the drupal.org REST tutorial for Drupal 8. I can now read and create new basic page and custom node records via REST calls.

Would someone please post a working example that demonstrates how to POST a new node record that populates an image field?

I've found a couple of examples that talk about uploading a file by base64 encoding it and POSTing a request to .../entity/file but all attempts to do this with Drupal 8.1.2 result in a 500 error response. If that is the correct first step to populating an image field, then a working example of how to post a file and then how to "attach" it to a node would be great.

Thanks.

Comments

postporncig’s picture

This is going to be in drupal 8.2
#1927648: Serialize file content (base64) to support REST GET/POST/PATCH on file entity

Meanwhile you can use RestUi and File Entity to achieve this

Read more here : http://drupal.stackexchange.com/questions/118106/how-to-send-files-to-drupal-8-via-rest

^ Read last post not accepted one !

hedeshy’s picture

Apparently, there is a problem with file POSTing in Drupal core at the moment. Try using JSON API module + JSON API File module as a temporary solution.
 For more information please read the following documentation.

shujat.munawar’s picture

* First of all you have to upload image.
* In response you will get tid value. 
* Then just call create rest API with image field and pass target id as the value of tid.

For more detailed information i have found very easy to understand an amazing article.
https://www.solutionspirit.com/create-article-content-with-image-rest-ap...