我从后端往前端传图片,用的servlet程序传回图片,采用将图片分块传回的方式,但是不知道为什么,大图片显示不成功,但是小图片可以,大图的话前端会显示

我的前端代码是通过此方式获取数据并显示:
js:
```javascript
const container = document.getElementById("mapDatabase");
container.innerHTML=data.map(item=>`
<div>
<p>地名: ${item.addressName}</p>
<p>时间: ${item.time}</p>
<p>方位: ${item.position}</p>
<img src="http://localhost:8080/demo1/getMap?id=${item.id}">
</div>
`).join('');
后端:
```java
public class GetMap extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("GetMap");
int id=Integer.parseInt(req.getParameter("id"));
System.out.println("id:"+id);
SearchMapDatabase searchMapDatabase=new SearchMapDatabase();
BufferedInputStream inputStream=searchMapDatabase.searchPhoto("hjw","2206410733",id);
byte[] photo=new byte[1024];
resp.setHeader("Cache-Control", "no-store");// 禁用缓存,避免加载旧数据
int length=0;
boolean checkMIMEType=false;//是否检查过图片类型
OutputStream out = resp.getOutputStream();
FileOutputStream fos=new FileOutputStream("E:\\photo.jpg");
while((length=inputStream.read(photo))!=-1){
if(!checkMIMEType){
String mimeType = detectMimeType(photo);
resp.setContentType(mimeType);
checkMIMEType=true;
System.out.println("mimeType:"+mimeType);
}
out.write(photo,0,length);
out.flush();
fos.write(photo,0,length);
}
out.close();
inputStream.close();
fos.close();
}
public static String detectMimeType(byte[] data){
// 检测 JPEG (FF D8 FF)
if ((data[0] & 0xFF) == 0xFF && (data[1] & 0xFF) == 0xD8) {
return "image/jpeg";
}
// 检测 PNG (89 50 4E 47 0D 0A 1A 0A)
if (data[0] == (byte)0x89 && data[1] == (byte)0x50
&& data[2] == (byte)0x4E && data[3] == (byte)0x47) {
return "image/png";
}
// 其他类型...
return "application/octet-stream";
}
}