mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
📝
This commit is contained in:
@@ -27,43 +27,35 @@ public class LocUpdateImg {
|
||||
return isDele;
|
||||
}
|
||||
|
||||
public static ReturnImage ImageuploadLOC(Map<String, File> fileMap, String username,Integer keyID) throws Exception {
|
||||
KeysServiceImpl keysService = SpringContextHolder.getBean(KeysServiceImpl.class);
|
||||
final Keys key = keysService.selectKeys(keyID);
|
||||
public static ReturnImage ImageuploadLOC(
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
String filePath =GlobalConstant.LOCPATH + File.separator;
|
||||
File file = null;
|
||||
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
System.out.println("待上传的图片:"+username + File.separator + ShortUID + "." + entry.getKey());
|
||||
File dest = new File(filePath + username + File.separator+ ShortUID + "." + entry.getKey());
|
||||
File temppath = new File(filePath + username+ File.separator );
|
||||
String filePath = GlobalConstant.LOCPATH + File.separator;
|
||||
try {
|
||||
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
File dest = new File(filePath + username + File.separator + ShortUIDName + "." + prefix);
|
||||
if (!dest.getParentFile().exists()) {
|
||||
dest.getParentFile().mkdirs();
|
||||
dest.getParentFile().mkdirs();
|
||||
}
|
||||
try {
|
||||
InputStream fileInputStream = new FileInputStream(entry.getValue());
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
|
||||
byte[] bs = new byte[1024];
|
||||
int len;
|
||||
while ((len = fileInputStream.read(bs)) != -1) {
|
||||
bos.write(bs, 0, len);
|
||||
}
|
||||
bos.flush();
|
||||
bos.close();
|
||||
returnImage.setImgname(username + "/" +ShortUID + "." + entry.getKey());//entry.getValue().getOriginalFilename()
|
||||
returnImage.setImgurl(key.getRequestAddress() +"/ota/"+username + "/" + ShortUID + "." + entry.getKey());
|
||||
returnImage.setImgSize(entry.getValue().length());
|
||||
returnImage.setCode("200");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
returnImage.setCode("500");
|
||||
System.err.println("上传失败");
|
||||
InputStream fileInputStream = new FileInputStream(entry.getValue());
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
|
||||
byte[] bs = new byte[1024];
|
||||
int len;
|
||||
while ((len = fileInputStream.read(bs)) != -1) {
|
||||
bos.write(bs, 0, len);
|
||||
}
|
||||
bos.flush();
|
||||
bos.close();
|
||||
}
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
returnImage.setCode("500");
|
||||
System.err.println("上传失败");
|
||||
}
|
||||
return returnImage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user