Score:0

How to POST file with JSON:API in /jsonapi/file/file?

gw flag

I tried with POSTMAN to upload a file to my endpoint host/jsonapi/file/file, the POST method is available but when I try to upload something, drupal gives me a 415 unsupported media type error. I tried with the binary option and with the data-form option using the next headers:

"Accept: application/vnd.api+json"
"Content-Type: application/octet-stream"
'Content-Disposition: file; filename="test.jpg"'

The GET method works well. It returns me all the files.

What is wrong?

cn flag
Did you [check the docs](https://drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/file-uploads)? Make sure that your user has permission to post files in the first place, too.
JPcode avatar
gw flag
I found the way using the relationship field and the endpoint of that relationship, it can't be done directly to the jsonapi/file/file endpoint.
cn flag
Glad you found the answer. Feel free to post an answer to your own question; doing so is welcomed and encouraged here.
Score:0
gw flag

To upload a file I just change the endpoint "host/jsonapi/file/file" for "host/jsonapi/node/[my_specific_name]/[relationship_field_name]" with the binary option in the body of the POST in POSTMAN.

Also this documentation was really helpful docs

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.