JSON_RPC Service: node creation and file attachment

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
g.k's picture

I am trying to upload a file as cck attachment to a new node using JSON_RPC service. The file gets uploaded to the Drupal file system but it's blank, 0 byte file. I think problem lies somewhere in encoding and may be it's a TI api issue. I submitted a question"How to convert a Titanium Blob to string?" on their forum but also want to check with the Drupal community and see if anybody else faced the same issue. Here is the code

function upload_image(media){

    //the file i want to send
    var file = {
        file: Test,
       
        filename: "test27.jpeg",
        filepath: "files/test27.jpeg",
        filesize: media.size,
        timestamp: String(date.getTime()),
        uid: uid,
        status: 0,
        filemime: ".jpeg"
    };
    //the args i send i the jsonrpc
    var args = {
        file: file
       
    };
    //a basic fonction give the method the args calculate the hash ...
    jsonrpc.request("file.save", args, function(){
   
        Titanium.API.info(this.responseText);
        information = eval('(' + this.responseText + ')');
       
        Titanium.API.info(information.result);
        var node = {
            type: "image",
            title: "image upload",
            field_image: {
                fid: information.result,
                filemime: ".jpeg",
                filesize: media.size,
                timestamp: String(date.getTime()),
                uid: uid,
                status: 1,
                list: 1,
                filename: "test27.jpeg",
                filepath: "files/test27.jpeg"
            }
       
       
        };
        args = {
            node: node
        
        };
       
        //saving the node
        jsonrpc.request("node.save", args, function(){
            Titanium.API.info(this.responseText);
            information = eval('(' + this.responseText + ')');
            Titanium.API.info(information);

Comments

(I posted an answer to the

korayal's picture

(I posted an answer to the issue on Appcelerator, but It was strictly about the Titanium side, so I think It should be healthier to post my reply about Drupal here)

I was wondering if you were using the modified JSON-RPC module which is provided on articles about Titanium and Drupal.

May I please ask about your Services and JSON module versions?

Because I am using the modified version + Services 1.x and I'm having issues about creating nodes, since when you send an object as an argument in node.save, the JSON parser doesn't work as expected. So the JSON-RPC service returns with error.

So I switched to XMLRPC which is not very practical. I would be glad if I learn that there is a resolution to this issue.

Finally, my question is if you managed to save a node (with an existing file's fid) with JSON-RPC?

Since I am trying to do something similar, maybe we could cooperate for a resolution.

I am not using the

g.k's picture

I am not using the JSON_Server or modified version of JSON_Sever instead using the JSONRPC Server 6x.1.3 which works in Services 6x.2.4. I am able to create a node using node.save and as I mention upload the file stub, it's the Base64 format that might be the main issue.

Titanium API

Group organizers

Group notifications

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

Hot content this week