Java代码 :
@RestController
@RequestMapping(value = "/api")
public class ImagesController extends BaseController {
// @PathVariable("name") /images/{name} /usr/local/cci/files/images/ C://excel//
@ApiOperation("获取图片")
@GetMapping(value = "/images/{name}")
public JSONData getImages(@PathVariable("name") String name,HttpServletRequest request, HttpServletResponse response) throws Exception {
// System.out.print(name);
// File f = new File("C://excel//"+name);
String file = "/usr/local/cci/files/images/" + name;
String suffix = name.substring(name.lastIndexOf(".")+1);
FileInputStream fileInputStream = new FileInputStream(file);
int size = fileInputStream.available();
byte[] bytes = new byte[size];
fileInputStream.read(bytes);
fileInputStream.close();
if (suffix.equals("jpg")){
response.setContentType("image/jpeg;charset=utf-8");
} else if (suffix.equals("png")){
response.setContentType("image/png;charset=utf-8");
} else if (suffix.equals("gif")){
response.setContentType("image/gif;charset=utf-8");
} else if (suffix.equals("mp3")){
response.setContentType("image/mp3;charset=utf-8");
} else if (suffix.equals("mp4")){
response.setContentType("image/mp4;charset=utf-8");
}
OutputStream outputStream = response.getOutputStream();
outputStream.write(bytes);
outputStream.close();
return null;
}
}