The image data returned by express is garbled.

the front desk requests to download a picture, and the back end downloads it through res.download. The data returned to the front desk is garbled

data:JFIFHHC%-sharp , -sharp&")*)-0-(0%()(C(((((((((((((((((((((((((((((((((((((((((((((((((((>..
rrMsg:"request:ok"
header:
Accept-Ranges:"bytes"
Cache-Control:"public, max-age=0"
Connection:"keep-alive"
Content-Disposition:"attachment; filename="1525056024543.jpg""
Content-Length:"10963"
Content-Type:"image/jpeg"
Date:"Mon, 30 Apr 2018 12:40:48 GMT"
ETag:"W/"2ad3-163146c2fee""
Last-Modified:"Mon, 30 Apr 2018 02:40:24 GMT"
X-Powered-By:"Express"
__proto__:Object
statusCode:200
__proto__
:
Object
Mar.07,2021

download files do not use ajax, use window.open (url), or window.location.href=url
if the download request is post, you can add form to document to achieve


previously answered similar questions, the back end returned to you is a binary jpg file, you can see the garbled "JFIF" is very conspicuous, that is the JPEG format of the file header.

Menu