2014-02-11 24 views
0

我試圖用drupalgap將圖像從android模擬器保存到drupal網站,但我無法做到這一點,下面是我寫的保存數據到drupal網站的ajax調用。使用drupalgap將圖像保存到drupal網站

我的AJAX調用

$.ajax({ 
       url: "http://192.168.1.146/drunew/?q=my_services/node.json", 
       type: 'post', 
       data: 'node[type]=drupalgap&node[title]=' + encodeURIComponent(title) + '&node[language]=und&node[body][und][0][value]=' + encodeURIComponent(body) + '&node[files][field_filef_und_0]=' + encodeURIComponent(filef), 
       dataType: 'json', 
       beforeSend: function (request) { 
         request.setRequestHeader("X-CSRF-Token", token); 
        }, 
       error: function(XMLHttpRequest, textStatus, errorThrown) { 
       alert('page_node_create_submit - failed to login'); 
       console.log(JSON.stringify(XMLHttpRequest)); 
       console.log(JSON.stringify(textStatus)); 
       console.log(JSON.stringify(errorThrown)); 
       }, 
       success: function (data) { 

       $.mobile.changePage("main.html", "slideup"); 
       } 
      }); 

但上面的代碼是不工作的文件中的字段,然後做一些[R & d我知道,首先我們必須得到裂後,然後將其保存。

下面是創建圖像的fid後的回覆。

{"fid":"47","uri":"http://192.168.1.146/drunew/my_services/file/47"} 

這裏我懷疑是如何集成在我上面的Ajax調用保存的圖像在Drupal站點的回覆。

任何幫助,感謝..

回答

0

一旦你的文件ID,你通過與節點一起創建/更新的資源,像這樣:

節點上創建 - POST

http://www.example.com/?q=drupalgap/node.json&title=Hello&type=article&field_images[und][0][fid]=47 

節點更新 - PUT

http://www.example.com/?q=drupalgap/node/123.json&field_images[und][0][fid]=47 

僅供參考,此功能現在內置到DrupalGap內核中,所以您在添加/編輯節點時不需要做太多的工作。