I'm currently building an app using ProcessWire. I'm using the ServicePages module to expose my data as a REST-like API.
However, all files seem to be outputted like this:
reel_poster: {
basename: "breakdown-2015-poster.jpg",
description: "",
tags: "",
formatted: false,
modified: 1468541707,
created: 1468541707
}
How do I get the actual path / URL of the file referenced? I need to get the path in a JS app, so I can't use the PHP API.
I've also posted this on their forums, but it seems like there's not a lot of activity there.
So, if I read this forum post correctly, the only way to create the URL is by assembling it manually. We need three things to do that:
We know that the base path for file assets is /site/assets/files/
. We can then do this, given that we have a page
object from the API:
var basePath = '/site/assets/files/';
var imagePath = basePath + page.id + '/' + page.image_field.basename;
This should work. I think. Yes. This is tested and works.