I am using Drupal services and services_entity module to build a web service. The problem is that when a file is attached to an entity using fields, etc, the service endpoints display the file as resource reference as:
array (
resource: file,
id: xx,
uri: /entity_file/xx.json
)
The thing is, every time you wish to display a file you will have to make 2 or more requests:
- First, get the file entity URI
- Second, retrieve the details of the file entity by id to get the direct url for the file (which can be embedded into the application or used as src="xx" for an img tag.
The question is, how to get the file URLs directly without having to make additional requests. So, the preferred response would be:
array (
resource: file,
id: xx,
uri: /entity_file/xx.json,
url: http://.../sites/.../files/foo/bar/b-reft.jpg
)
I looked for hours but did not find an answer, so I thought I would share the solution I found. I believe it would help many (and I also wish I could share my module for complex index query parameter support for services_entity module).