我有一个 API 请求 URL,它将自动从浏览器下载并保存 QRcode 图像。
它的Content-Type是application/jpeg,它的形式是这样的:
application(websiteURl)/egs?cmd=gen_qrcode&customer_id=123&name=abc
斜杠之前是我的应用程序的 URL,然后是请求的键和值对。
当我在浏览器上发布此内容时,它会自动下载 QRcode jpg。 但是,我想将图像转换为 jpg(或其他图像类型)以显示在我的 Web 应用程序上,但不想保存它。
当我使用 PostMan 并保存文件时,它会给我标题信息:
Content-Disposition: attachment; filename="filename.jpg";
Content-Type: application/jpeg;
我正在使用 javascript 和 Vue, 我想知道是否有办法阻止自动保存并显示图像。
最佳答案
根据我在网上找到的信息,application/jpeg
不是有效的 Content-Type
header 。您应该使用相应的 header image/jpg
或 image/jpeg
。
参见Is the MIME type 'image/jpg' the same as 'image/jpeg'?和 https://www.w3.org/Graphics/JPEG/
编辑:
您可能还想尝试手动设置(或取消设置)您的 Content-Disposition
header 。
关于javascript - 显示内容类型: application/jpeg result on webpage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59565945/