use of com.zyd.blog.file.FileUploader in project OneBlog by zhangyd-c.
the class BizArticleServiceImpl method publish.
/**
* 发布文章
*
* @param article
* @param tags
* @param file
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean publish(Article article, Long[] tags, MultipartFile file) {
if (null == tags || tags.length <= 0) {
throw new ZhydArticleException("请至少选择一个标签");
}
if (null != file) {
FileUploader uploader = new GlobalFileUploader();
VirtualFile virtualFile = uploader.upload(file, FileUploadType.COVER_IMAGE.getPath(), true);
// 保存封面图片
article.setCoverImage(virtualFile.getFilePath());
}
Long articleId = null;
if ((articleId = article.getId()) != null) {
this.updateSelective(article);
} else {
article.setUserId(SessionUtil.getUser().getId());
articleId = this.insert(article).getId();
}
if (articleId != null) {
articleTagsService.removeByArticleId(articleId);
articleTagsService.insertList(tags, articleId);
}
return true;
}
use of com.zyd.blog.file.FileUploader in project OneBlog by zhangyd-c.
the class RestApiController method uploadFile.
@BussinessLog("wangEditor编辑器中上传文件")
@RequiresPermissions("article:publish")
@PostMapping("/uploadFile")
public ResponseVO uploadFile(@RequestParam("file") MultipartFile file) {
FileUploader uploader = new GlobalFileUploader();
VirtualFile virtualFile = uploader.upload(file, FileUploadType.SIMPLE.getPath(), true);
return ResultUtil.success("图片上传成功", virtualFile.getFullFilePath());
}
use of com.zyd.blog.file.FileUploader in project OneBlog by zhangyd-c.
the class BlogAdminApplicationTests method uploadFile.
@Test
public void uploadFile() {
FileUploader uploader = new GlobalFileUploader();
File file = new File("C:\\Users\\yadon\\Desktop\\新建文件夹\\web-index-pc.png");
VirtualFile virtualFile = uploader.upload(file, FileUploadType.SIMPLE.getPath(), true);
System.out.println(virtualFile);
}
use of com.zyd.blog.file.FileUploader in project OneBlog by zhangyd-c.
the class ImageDownloadUtil method saveToCloudStorage.
/**
* 将网络图片转存到云存储中
*
* @param imgUrl 网络图片地址
* @param referer 为了预防某些网站做了权限验证,不加referer可能会403
*/
public static String saveToCloudStorage(String imgUrl, String referer) {
log.debug("download img >> %s", imgUrl);
String res = null;
try (InputStream is = getInputStreamByUrl(imgUrl, referer)) {
FileUploader uploader = new GlobalFileUploader();
VirtualFile file = uploader.upload(is, FileUploadType.SIMPLE.getPath(), imgUrl, false);
res = file.getFullFilePath();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new GlobalFileException(e.getMessage());
}
return res;
}
use of com.zyd.blog.file.FileUploader in project OneBlog by zhangyd-c.
the class SysConfigServiceImpl method saveFile.
@Override
@RedisCache(flush = true, enable = false)
public void saveFile(String key, MultipartFile file) {
if (key == null) {
return;
}
if (file != null) {
FileUploader uploader = new GlobalFileUploader();
VirtualFile virtualFile = uploader.upload(file, FileUploadType.QRCODE.getPath(), true);
this.saveConfig(key, virtualFile.getFullFilePath());
}
}
Aggregations