/**
* 服务器获取图片下载保存(暂时不需要存储)
* @param imgList(图片集合类)
*/
public static List<?> serviceFileDownload(List<String> imgList){
/**
* 1.从前端获取****上传图片路径
* 2.通过路径从*******服务器下载图片到本地,
*
*/
// String fileUrl = "http://static.dingtalk.com/media/lADPBbCc1W.jpg";//测试用例
List<String> listImg = new ArrayList<String>();
if(imgList == null){
logger.error("imgList集合为空[{}]",JSON.toJSONString(listImg));
return null;
}
for(String img : imgList){
try{
URL url = new URL(img);
HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection();
int respones = httpUrl.getResponseCode();
if(respones == HttpURLConnection.HTTP_OK){
logger.info("从服务器下载图片调用成功返回参数为:[{}]",respones);
InputStream inputStram = httpUrl.getInputStream();
int fileLength = img.lastIndexOf("/")+1;
String courrenFileName = img.substring(fileLength);
String fileNameNew = courrenFileName.replaceAll("/", "");
inputStram.close();
listImg.add(fileUrlAddress);
}
httpUrl.disconnect();
}catch(Exception e){
e.printStackTrace();
}
}
return listImg;
}