Hey all, I'm trying to setup a WireMock mapping fo...
# help
a
Hey all, I'm trying to setup a WireMock mapping for returning a png image like following:
Copy code
{
  "request": {
    "method": "GET",
    "urlPath": "/test/img"
  },
  "response": {
    "status": 200,
    "bodyFileName": "wiremock.png"
  },
  "metadata": {
    "name": "file-stub"
  }
}
And I have the
wiremock.png
file in
__files
folder. Although its not working when I request
<http://localhost:8080/test/img>
in my browser. Any ideias? I'm using latest wiremock docker image Thanks in advance ✌️
l
I am a little puzzled by this because I have just tried this myself and it works fine. How are you starting up the container and are there any error messages?
Also, could you post the image you are using?
I added this example here as an example of what is working for me. Does this work for you ? - https://github.com/leeturner/wiremock-standalone-docker-example/blob/main/wiremock/mappings/return-image.json
👎 1
t
It’s usually a good idea to set a content type header of e.g.
image/png
in a case like this, otherwise the browser won’t realise it’s an image
l
I thought the same. Firefox seems to display the image regardless but not sure about other browsers
a
Hey literally this
Ya I tried setting it and doesn't work either with content-type
Tested with Google Chrome and Brave
l
Not sure why it isn't working for you to be honest. Could you try adding in the content type header and remove the
--global-response-templating
startup parameter. Depending on the image you are using it could be trying to interpret it as a handlebars template
👍 1
t
Yeah, don’t use
--global-response-templating
with images as it’ll try to resolve the image content as if it’s a template.
a
Ya
Thats it 😓
l
Nice !!
a
can I disable it for specific stubs?
t
You can enable it for specific stubs
a
Ya that I know 😛
t
Add
"transformers": ["response-template"]
to your stub response
🙌 1
a
Thanks for the help guys! 💪
👍 1
t
Actually, there is a way to specifically disable body templating for specific stubs
👀 1
l
No worries. Glad we got to the bottom of it
🙌 1
a
Does setting
"transformers": []
work?
t
You might need to check the docs for that as I can’t remember the syntax and I’m on a train with terrible wifi at the moment
😂 1
No, that won’t work
There’s another syntax entirely specifically for turning off body templating
a
Found it
disableBodyFileTemplating: true
on parameters
t
Yep, that’s the one
Transformer parameters, yes
a
Thanks again!
🙌 1