0

I need to add content trough a node.create and one of the fields in the content type I am adding is a file field. So far I have been able to get my Services module set up with REST server to accept user and node resources and I have been able to make http-requests to add content containing text fields. Now I need to expand on this to work with a file field but I have not been able to find any resources about creating nodes that contain file fields. I am wondering how would this be done? Would it be done in one pass or two? Would I upload the file with a first post then do the association next? Does anyone have any good resources related to this topic?

1 Answer 1

4

Currently services doesn't offer the ability to add a file to a node in ONE method call, but thats easily within the scope of what services can offer, its just not in services core.

Currently you can make a request to create a file and get the returned FID, then you can process to submit a node with the field structure for a file field.

Which is something like

{"nid":1, "field_image":{"und":[{"fid":2}]}}

Forgive me thats very rough, but you can can use devel to look at an already existing node with an image attached and mimic that in your submission and it will work.

The current process is:

POST to /file

get returned FID

PUT to /node make sure to have nid and field_* in the correct structure or it won't stick.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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