Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 使用drupalgap将图像保存到drupal站点_Image_Drupal 7_Save - Fatal编程技术网

Image 使用drupalgap将图像保存到drupal站点

Image 使用drupalgap将图像保存到drupal站点,image,drupal-7,save,Image,Drupal 7,Save,我试图使用drupalgap将一个图像从android emulator保存到drupal站点,但我无法做到这一点,下面是我编写的ajax调用,用于将数据保存到drupal站点 我的AJAX调用 $.ajax({ url: "http://192.168.1.146/drunew/?q=my_services/node.json", type: 'post', data: 'node[type]=drupalga

我试图使用drupalgap将一个图像从android emulator保存到drupal站点,但我无法做到这一点,下面是我编写的ajax调用,用于将数据保存到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");
              }
          });
但是上面的代码不适用于文件字段,在做了一些研究和开发之后,我知道首先我们必须获得fid,然后保存它

下面是为图像创建fid后的响应

{"fid":"47","uri":"http://192.168.1.146/drunew/my_services/file/47"}
在这里,我的疑问是如何将这个响应集成到我上面的ajax调用中,以便在drupal站点中保存图像


任何帮助,谢谢。

一旦您有了文件ID,您可以将其与节点创建/更新资源一起传递,如下所示:

节点创建-发布

http://www.example.com/?q=drupalgap/node.json&title=Hello&type=article&field_images[und][0][fid]=47
节点更新-放置

http://www.example.com/?q=drupalgap/node/123.json&field_images[und][0][fid]=47
仅供参考,此功能现在内置于DrupalGap核心中,因此在添加/编辑节点时不需要做太多工作