Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关闭文件流,解决删除文件失败导致apk无法上传 #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/main/java/org/yzr/service/AppService.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,28 @@ private App getApp(User user, Package aPackage) {
private void storeFiles(String filePath, Package aPackage) throws IOException {
// 2.1 源文件
File sourceFile = new File(filePath);
Storage storage = storageUtil.store(new FileInputStream(sourceFile), sourceFile.length(), "application/octet-stream", sourceFile.getName());
FileUtils.forceDelete(sourceFile);
FileInputStream sourceFileInputStream = new FileInputStream(sourceFile);
Storage storage = storageUtil.store(sourceFileInputStream, sourceFile.length(), "application/octet-stream", sourceFile.getName());
try{
sourceFileInputStream.close();
FileUtils.forceDelete(sourceFile);
}catch(Exception e){
e.printStackTrace();
}
aPackage.setSourceFile(storage);
// 2.2 图标文件
String iconFilePath = PathManager.getTempFilePath("png");
ImageUtils.resize(aPackage.getIconFile().getUrl(), iconFilePath, 192, 192);
File iconFile = new File(iconFilePath);
Storage iconStorage = storageUtil.store(new FileInputStream(iconFile), iconFile.length(), "application/png", iconFile.getName());
FileUtils.forceDelete(new File(aPackage.getIconFile().getUrl()));
FileUtils.forceDelete(iconFile);
FileInputStream iconFileInputStream = new FileInputStream(iconFile);
Storage iconStorage = storageUtil.store(iconFileInputStream, iconFile.length(), "application/png", iconFile.getName());
try {
iconFileInputStream.close();
FileUtils.forceDelete(new File(aPackage.getIconFile().getUrl()));
FileUtils.forceDelete(iconFile);
}catch(Exception e){
e.printStackTrace();
}
aPackage.setIconFile(iconStorage);
}
}