Services Questions and Opportunities

Events happening in the community are now at Drupal community events on www.drupal.org.
kaw3939's picture

Hello,

I need a little advice and maybe some help.

Here are the requirements:

  1. I have a media encoding server that needs to send a video file to the Drupal server and create a node.
  2. I need to provide a sample request that is formatted to push file into Drupal and create a node.

This is going to be for a project released on DO that relies on the services module.

What do you think the issues will be with this?

What is the file struct that has to be provided in JSON format to fill out the field:

struct file (required)
An object representing a file
This is on the page that I browse the service with.

I've worked with services before to create nodes, but I haven't done it with saving files.

The main requirement that i'm working under is that the file needs to be "pushed" into drupal from the media encoding server. They do not want to allow Drupal to download / pull the file from the server to Drupal.

Any help would be appreciated. I help organize the Norther New Jersey Drupal group and will be coming to the NYC meetup next month. Any help or advice would be appreciated. This may also turn into a paid project, so I may be able to throw some $$ someones way, if they help out with this.

Comments

Hi kaw3939, I have worked

brutuscat's picture

Hi kaw3939, I have worked with the services module before. Which version of drupal and the services module are you using?

solution?

brutuscat's picture

Well, I was taking a look at the source of the upload module and the node.save service of the services module. The node.save uses the node_form_submit, so the file will be processed like in a normal post.

This is not so good for you since in a normal post the upload module will hook the node_form_submit and use the file_save_upload function to process the file upload and build the file object. The file_save_upload function processes the file's data using the $_FILE var. This var is handled by php. So it can't be done directly using RPC, since oyu should send the json or xml data and a the application/x-www-form-urlencoded data of the file to be processed by php. And that wouldn't work I guess...

So my advice is to create a custom service that reads the file in a special field (base64 encoded in a json/xml field) and you also send all the node fields you want. Then within your service, create the node using the node_service_save callback and after that you process the file, build the file object and update the node with the created file.

Take a look at this to set a file programatically into a node http://workingdirectory.net/posts/2009/attach-file-to-node-drupal-6/

Let me know if you need more help coding I am open to oportunities ;)

Regards,
Mauro

The rest server can accept

voxpelli's picture

The rest server can accept true files being posted to it - that is the body of the http-request to the rest server is the raw file (and the content-type header of course gives info about what kind of file it is).

I can't find any example right now on how to accomplish it though - but I would suggest looking into the rest server.

thanks

kaw3939's picture

I got some ideas from this

I've done something similar

bsenftner's picture

I've done something similar where a Services exposed API receives the URL to an encoded video, and then the receiving module's logic simply used that URL with cURL to slerp the file into the Drupal host's file system. Now, technically, that is pulling... which you say you're not allowed to do...

I've also done a Services exposed API that gets binary files in the neighborhood of 1-5MB sends them as one of the Services API parameters. I had to modify the "Token expiry time" setting in Services Settings to prevent timeouts, but it works. Someone on the Services Issue queue mildly scolded me, saying that Services was not designed for such usage, but it it works... so why not?

(BTW, if anyone has any advice as why having large binary payload as a parameter to a Services exposed routine is BAD, I'd love to know what they are. My 'scolding' did not include such points.)

File.save?

waldmanm's picture

Have you looked at File.save? I might be missing something, and I haven't used it myself yet, but it seems to support your requirement (along with node.save and a module such as filefield).

BTW, the file.save method description is misleading in that it states:
"Note this does not save files themselves, just the information as stored in the files table."
but a patch has been committed a while back which actually does allow saving the file itself - see http://drupal.org/node/376226.

HTH,
Micah

Thanks

kaw3939's picture

This information helps a lot. The deadline for this feature was pushed back and I may end up just rolling my own solution because services has dependencies and what I need can be accomplished with something fairly simple. Also I need to send back information to the sending server. This project is going to be released on Drupal.org and I'll post a link to that here, so you can see what I did.

Just want to mention that the

voxpelli's picture

Just want to mention that the REST Server has a parser called fileRecieve() that can receive a file in a resource without base64-encoding it. I've now found an example of it's usage.

Call me silly

kaw3939's picture

What is the deal with base64 encoding? Why is it needed?

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: