0

I have an API request URL, which will automatically download and save a QRcode image from the browser.

Its Content-Type is application/jpeg, and its form is like this:

application(websiteURl)/egs?cmd=gen_qrcode&customer_id=123&name=abc

Before the slash is my app's URL, and then it is the request's key and value pairs.

When I post this on the browser, it will automatically download a QRcode jpg. However, I want to get the image to jpg(or another image type) to display on my web application and don't wanna save it.

When I use PostMan and save the file, it give me the header informations:

Content-Disposition: attachment; filename="filename.jpg";
Content-Type: application/jpeg;

I am using javascript and Vue, I wonder if there is a way to prevent the autosave and display the image.

Karthick Ram
  • 363
  • 4
  • 11
Judith
  • 3
  • 2

2 Answers2

1

From what I can find online, application/jpeg is not a valid Content-Type header. You should use the according header image/jpg or image/jpeg.

See Is the MIME type 'image/jpg' the same as 'image/jpeg'? and https://www.w3.org/Graphics/JPEG/

EDIT: You may also want to try to manually set (or unset) your Content-Disposition header.

BRO_THOM
  • 754
  • 8
  • 22
  • I do not wrote this `application/jpeg` and `Content-Type`, I wanna know may I change this in my javascript? – Judith Jan 02 '20 at 16:15
  • What kind of application are you using as a server? – BRO_THOM Jan 02 '20 at 16:16
  • I am using Vue and Node.js for frontend, backend is java spring. – Judith Jan 02 '20 at 16:19
  • Well if you have the URL for the image, you could use an '' element to refer to the image URL? – BRO_THOM Jan 02 '20 at 16:53
  • Thanks for your reply. But I have tried the src of '' element, and it just give me a broken photo. I think it's not a valid type of image, so the '' element can not read it. – Judith Jan 02 '20 at 17:18
  • That is basically the same issue as with the header probably. Maybe you should find a node library to generate QR-images for you so you have more control over them. – BRO_THOM Jan 02 '20 at 17:20
  • Thanks for your advice, I will search the information about that. – Judith Jan 02 '20 at 17:27
0

In addition to the invalid Content-Type you're using, Content-Disposition: attachment tells the browser to save it instead of showing it. Remove that.

ceejayoz
  • 165,698
  • 38
  • 268
  • 341
  • The response is from another website, could I change the `Content-Disposition` at my side(client side)? – Judith Jan 02 '20 at 16:13