I am using the Services module and views.getView method to distribute content from a central Drupal site to various locations. It is a brilliant solution! Hats off to the maintainers of this fantastic project!
However, while I can transfer entire nodes beautifully, files are an issue. Which leads me on to my "wouldn't it be nice if ....?"
Wouldn't it be nice if someone provided another service: file_service.
file_service would use the Drupal File Interface to send files over xml-rpc. The most basic method would receive a local path and return the file if it exists, call it file.getFile. However, it would also include support for sending files attached to a node, say file.getNodeFiles. Making it work with the core Upload module would be an obvious start (pass a node id and get back an array containing the files attached to the corresponding node), but future support could include CCK FileField and CCK ImageField as well as the Image module.
Any takers?? ;-)
Comments
Comment #1
greg.harveyActually, this was way easier than I thought. The code below is for a module called 'file_service.module' which exposes a service that, when passed a node id, passes back an array of base64_encode()'d files:
There are many additions you could make to this module, but this is all I'll probably do for now. Obviously, you need to base64_decode() the items in the array when you are at the client side. My quick test code on the client looked like this:
Comment #2
brmassa commentedGreg,
it has not a access check. Which means that anyone will be able to get those files!
regards,
massa
Comment #3
greg.harveyGood point! I'll build one in. =)
EDIT: anyone with an API key - I have API keys on, so I didn't worry about access too much.
Comment #4
greg.harveyNew version:
Comment #5
brmassa commentedGreg,
commited.
regards,
massa
Comment #6
greg.harveyThanks. Will post my image service too at some point.
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #8
darrenmothersele commentedI'd be interested to see how far you got with the ImageField service as I'm in need of something similar and about to start work on implementing something.
To be more specific I have a node import solution that imports from a specific XML format and I am looking at moving this to using the services module (rather than executing within a bootstrapped drupal environment and using drupal_execute). The XML files reference images that are attached to the created nodes using ImageField.
If I am to move this across to using services I somehow need to augment node.save with support for attaching imagefields.
Comment #9
greg.harveyI finished it. Just haven't gotten around to posting it and it's at work (and I'm not!) ... I'll try and remember to post it tomorrow. =)
Comment #10
carlosg2 commentedThanks for share your Binary files service!
For the ImageField specifically would be posible to reference to a imagecache preset url?
Regards,
Carlos
Comment #11
greg.harveySee this new issue: http://drupal.org/node/310155#comment-1017328
Comment #12
drupalxykon commentedany chance of being backported to drupal 5?
Comment #13
greg.harveyNot by me, but it's a very simple module. Assuming the Services API is the same, there would be little difference. But I don't have any Drupal 5 sites to try it on any more, and I won't be creating one especially. Someone who uses Drupal 5 with services will need to pick this up.
Changed the status for you. =)
Comment #14
marcingy commentedThis will not be ported to D5.