2

前言

我正在构建一个 Drupal 站点,它兼作用 Flex 编写的移动应用程序的内容服务端点。CMS 负责存储许多项目,这些项目除其他字段外,还有一个表示节点的图像字段(如电影封面或小型产品镜头)。我正在使用服务模块和 REST 服务将此内容作为 JSON 提供给移动应用程序。

问题

我注意到 Drupal(或者可能是服务本身)限制了每个请求返回的数据量,似乎是基于请求的粒度。例如,节点索引请求仅返回每个节点或多或少相同的字段:nid、标题、状态等。而对单个节点的请求还返回自定义字段,包括我的图像字段。

我的问题是图像字段的 URI 值是“streamwrapped”(或者我在研究这个问题时看到过它),所以它被简单地列为public://images/node_image.jpg. 为了获得完整的 URI,我必须请求文件。这意味着对于移动应用程序中的索引页面,我必须发出1 + (n * 2)请求以获取有关给定节点的完整数据,以及n获取每个节点显示的图像的请求。对于给定的节点页面,最多n为 8 个,这意味着每页节点最多可以向服务器发出 25 个请求。

这是常见的/被接受的,还是有一种更简单/更快/不那么繁琐的方法可以在更少的请求中访问这些数据?

旁注:我注意到的一件事是文件请求返回了带有 base64 编码的图像数据库。我当然可以使用它来显示图像,但我更愿意只从服务器请求二进制图像。

例子

/end-point/node.json

    [
      {
        nid: "6",
        vid: "6",
        type: "page",
        language: "und",
        title: "Node 6 Title",
        ...snip...
        uri: "http://example.com/end-point/node/6"
      },
      {
        nid: "5",
        vid: "5",
        type: "game",
        language: "und",
        title: "Node 5 Title",
        ...snip...
        uri: "http://example.com/end-point/node/5"
      },
      ...snip...
    ]

/end-point/node/5.json

    {
      vid: "5",
      uid: "1",
      title: "Node 5 Title",
      ...snip...
      body: {
        und: [{
          value: "Lorem ipsum dolor sit amet.",
          summary: "Lorem ipsum...",
          format: "filtered_html",
          safe_value: "<p>Lorem ipsum dolor sit amet.</p>",
          safe_summary: "<p>Lorem ipsum...</p>"
        }]
      },
      field_artwork: {
        und: [{
          fid: "8",
          alt: "",
          title: "",
          width: "252",
          height: "272",
          uid: "1",
          filename: "node_image.jpg",
          uri: "public://images/node_image.jpg",
          filemime: "image/jpeg",
          filesize: "32653",
          status: "1",
          timestamp: "1329839925",
          rdf_mapping: []
        }]
      },
      ...snip...
    }

/end-point/file/8.json

    {
      fid: "8",
      uid: "1",
      filename: "node_image.jpg",
      uri: "public://node_image.jpg",
      filemime: "image/jpeg",
      filesize: "32653",
      status: "1",
      timestamp: "1329839925",
      rdf_mapping: [ ],
      uri_full: "http://example.com/sites/default/files/images/node_image.jpg",
      target_uri: "images/node_image.jpg",
      file: "..snip base64-encoded image data...",
      image_styles: [ ]
    }
4

1 回答 1

0

由于没有得到答复,我自己做了。
新模块Full URL file information将填写您要查找的信息。
更多详情请参阅我的博文——“ Drupal 文件信息,填写服务的 URL 信息”。

于 2013-04-22T09:19:43.090 回答