I’m trying to attach files (images) to nodes via Services 3 from an external app using JavaScript.
From what I understand (and doing) is:
1) Create a node posting JSON to my endpoint domain.com/api/node.json
{ "type":"foo", "title":"Hello World", "language":"und", "body":{"und":{"0":{"value":"Body Text"}}}, }
2) Create file posting JSON to my endpoint domain.com/api/file.json
{ "filename":"image.jpg", "target_uri":"public://image.jpg", "filemime":"image/jpeg", "file":"myBase64String" }
No problem at all at this point.
Then when trying to attach the files created to the node, is where I have trouble, not http errors, simply nothing happens.
First I have tried posting JSON to my endpoint domain.com/api/node/*nid/attach_file after successfully creating a new file, and getting back the fid
{ "field_name":"foo", "filename":"image.jpg", "fid":"*fid" }
Returning Status 200 OK empty text, but when viewing the node remains the same without the file attached.
I have also tried to create the files first and then when posting for node creation adding the fid, the node is created but no file attached.
{ "type":"foo", "title":"Hello World", "language":"und", "body":{"und":{"0":{"value":"Body Text"}}}, "field_foo":{"und":{"0":{"fid":"*fid"}}} }
My field is a field type Image, widget Image. I have also tried in another field type file, with same results.
If someone can give me a heads up, what am I doing wrong or what is missing. I can’t find any explanatory documentation on line.
Thank you.