Skip to content

Commit

Permalink
Merge pull request #48 from Andecheal/fix-transaction-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozzzi authored Dec 20, 2023
2 parents b70962f + 2299967 commit ef08584
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ public R<String> uploadFile(@RequestParam("file") MultipartFile file,
if (picture.getId() == null) {
return R.ok("上传失败");
}
try (InputStream inputStream = file.getInputStream()) {
return R.ok(osManager.put(picture.getPathName(), inputStream));
} catch (IOException e) {
e.printStackTrace();
}

return R.ok(picture.getUrl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.blossom.common.base.exception.XzException400;
import com.blossom.common.base.exception.XzException400HTTP;
import com.blossom.common.base.exception.XzException404;
import com.blossom.common.base.exception.XzException500;
import com.blossom.common.base.util.PrimaryKeyUtil;
import com.blossom.common.db.aspect.Pages;
import com.blossom.common.iaas.OSManager;
Expand All @@ -24,6 +25,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -183,6 +186,12 @@ public PictureEntity insert(MultipartFile file, String filename, Long pid, Long
}

baseMapper.insert(pic);
// 入库后进行文件上传操作
try (InputStream inputStream = file.getInputStream()) {
osManager.put(pic.getPathName(), inputStream);
} catch (IOException e) {
throw new XzException500("图片[" + pic.getPathName() + "]上传异常,请重试");
}
return pic;
}

Expand Down

0 comments on commit ef08584

Please sign in to comment.