I have read https://www.drupal.org/node/2941420 and I can upload a image file then use it in article.

But I can not use it as video field after I upload a video file.

My Drupal version is 8.6.0-beta2.

I use the media type ( Drupal 8 core module) for my video field, this is a Entity reference.

When I use

POST  http://www.myhots.com/file/upload/media/video/field_media_video_file?_fo...

I get the response as the end shows (the fid =47)

{
    "message":"Unprocessable Entity: validation failed.
field_user_video.0.target_id: The referenced entity (media: 47) does not exist.
"
}

Then I use it :

curl -X PATCH -H 'Content-Type: application/json' -H 'X-CSRF-Token:YYYYYYYYYYYYYYYYYYYY' -H 'Authorization: Basic XXXXXXXXXXX=' -i 'http://www.myhost.com/node/5?_format=json' --data '{

"type":[
    {
        "target_id":"user_video",
        "target_type":"node_type"
    }
],
"field_user_video":[
    {
        "target_id":47,
        "target_type":"media"
    }
]

}

The response is as follows:

{
    "message":"Unprocessable Entity: validation failed.
field_user_video.0.target_id: The referenced entity (media: 47) does not exist.
"
}

Which information should I use to patch it? It seems that the "fid" is not correct.

Maybe I need "target_id " of "media“, but there is no response after I upload a video file, any suggestion?

"field_user_video": [{
  "target_id": 3,
  "target_type": "media",
  "url": "\/d86\/media\/3"
}]

'

{
"fid":[
    {
        "value":47
    }
],
"uuid":[
    {
        "value":"cf69fac4-5ba2-4861-9cce-a959dee3c480"
    }
],
"langcode":[
    {
        "value":"en"
    }
],
"uid":[
    {
        "target_id":1,
        "target_type":"user",
        "target_uuid":"c2b09ff8-345a-43fa-b9ae-68af0c9cd3ea",
        "url":"/d86/user/1"
    }
],
"filename":[
    {
        "value":"example2.mp4"
    }
],
"uri":[
    {
        "value":"public://2018-08/example2.mp4",
        "url":"/d86/sites/default/files/2018-08/example2.mp4"
    }
],
"filemime":[
    {
        "value":"video/mp4"
    }
],
"filesize":[
    {
        "value":6320348
    }
],
"status":[
    {
        "value":false
    }
],
"created":[
    {
        "value":"2018-08-31T03:04:20+00:00",
        "format":"Y-m-d\TH:i:sP"
    }
],
"changed":[
    {
        "value":"2018-08-31T03:04:20+00:00",
        "format":"Y-m-d\TH:i:sP"
    }
]
}

after two days trying , i find the solution myself. shortly ,

first, post file , get the fid.

second, post a media , get the Mid (media id)

third , post a node ,use the Mid

I omit the second step.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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