How i want to upload image to my website as POST Request


#1

Hi Guys am glad to be using JSON API
i have question about POST request when i want to upload one image or more in my one FORM by JSON API so how i can do it ??
i read some article and posts about jsonapi and i figured out that i have to put in my URL
http://www.example.com/jsonapi/article/relationship/{related}
but i didn’t understand what related is mean??
and about my HEADER and MY body what i have to write except application/vnd.api+json and in my body
{
“data”:
{
“type”:“article”,
“relationship”:{
“field_image”:
{
“data”:
{
“type”: “file–file”,
“data”: “base64encoded”
}
}
}
}//end
something wrong and i didn’t got a result so…
if some one know about it ?? or he did it before could please share your information i will be pleasure to help me
Thanks :slight_smile:


#2

Upload using a compound document:

New article:

POST /articles
{ 
  "data": {
    "attributes": ...,
    "relationships": {
      "field_image": {
        "data": {"type": "file-file", "id": "some-generated-id"}
      }
    }
  }
  "included": [
    {
      "type": "file-file",
      "id": "some-generated-id",
      "attributes": {
        “data”: “base64encoded”
      }
    }
  ]
}

For existing article, the same applies, except it’s a PATCH and you only need the relevant part.

The server must be able to recognize the generated id and look for the corresponding data in the “included” part.