https://linen.dev logo
#help
Title
# help
a

André Martins

02/27/2024, 4:00 PM
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

Lee Turner

02/27/2024, 5:40 PM
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

Tom

02/27/2024, 9:34 PM
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

Lee Turner

02/27/2024, 9:36 PM
I thought the same. Firefox seems to display the image regardless but not sure about other browsers
a

André Martins

02/28/2024, 9:57 AM
Hey literally this
Ya I tried setting it and doesn't work either with content-type
image.png
Tested with Google Chrome and Brave
l

Lee Turner

02/28/2024, 10:05 AM
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

Tom

02/28/2024, 10:05 AM
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

André Martins

02/28/2024, 10:06 AM
Ya
Thats it 😓
l

Lee Turner

02/28/2024, 10:06 AM
Nice !!
a

André Martins

02/28/2024, 10:06 AM
can I disable it for specific stubs?
t

Tom

02/28/2024, 10:06 AM
You can enable it for specific stubs
a

André Martins

02/28/2024, 10:06 AM
Ya that I know 😛
t

Tom

02/28/2024, 10:06 AM
Add
"transformers": ["response-template"]
to your stub response
🙌 1
a

André Martins

02/28/2024, 10:06 AM
Thanks for the help guys! 💪
👍 1
t

Tom

02/28/2024, 10:07 AM
Actually, there is a way to specifically disable body templating for specific stubs
👀 1
l

Lee Turner

02/28/2024, 10:07 AM
No worries. Glad we got to the bottom of it
🙌 1
a

André Martins

02/28/2024, 10:08 AM
Does setting
"transformers": []
work?
t

Tom

02/28/2024, 10:08 AM
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

André Martins

02/28/2024, 10:10 AM
Found it
disableBodyFileTemplating: true
on parameters
t

Tom

02/28/2024, 10:11 AM
Yep, that’s the one
Transformer parameters, yes
a

André Martins

02/28/2024, 10:12 AM
Thanks again!
🙌 1
6 Views