AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
222 stars 20 forks source link

jpeg image response is not being previewed #252

Closed jroeber closed 5 months ago

jroeber commented 5 months ago

I have a simple REST API where I post an image:

### Post blue square

POST http://localhost:3000/api/file
Content-Type: multipart/form-data; boundary=abcd1234xyz

--abcd1234xyz
Content-Disposition: form-data; name="file"; filename="file"
Content-Type: image/jpeg

< sample-blue-200x200.jpg
--abcd1234xyz--

This saves the file and returns the hash, which I can use to get the file later:

### Get blue square

GET http://localhost:3000/api/file/78a039dc0213925f606354b4eb2248e86e0045825684bbab05108d05081ea7ad

However, when I run this with httpYac, I get an error message saying that the response appears to be binary (which is correct) and that it cannot be displayed as text (which is also correct):

image

I thought maybe my Content-Type response header may not be set correctly, so I tried cURL to see:

jon@desktop:~$ curl -v http://localhost:3000/api/file/78a039dc0213925f606354b4eb2248e86e0045825684bbab05108d05081ea7ad
* Host localhost:3000 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:3000...
* Connected to localhost (::1) port 3000
> GET /api/file/78a039dc0213925f606354b4eb2248e86e0045825684bbab05108d05081ea7ad HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Cache-Control: max-age=0
< Content-Type: image/jpeg
< Vary: Origin
< Date: Thu, 11 Jan 2024 23:55:16 GMT
< Content-Length: 1020
< 
Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.
* Failure writing output to destination
* Closing connection

...But it looks like the Content-Type is set correctly in the response headers, and yet the response isn't rendered in VS Code. This request works fine in humao's REST Client.

jroeber commented 5 months ago

If it helps, I'm running Linux Mint 21.2 with VS Codium 1.85.1. I tried manually adding # @openWith imagePreview.previewEditor to the request as shown in the docs, but that didn't seem to change anything.

AnWeber commented 5 months ago

thx for the report. I just forgot to await the save of the file. This is needed to open a image in previewEditor. I added it and it is fixed with next release.