Search in sources :

Example 1 with FileUploader

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;
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) ZhydArticleException(com.zyd.blog.framework.exception.ZhydArticleException) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with FileUploader

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());
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 3 with FileUploader

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);
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) VirtualFile(com.zyd.blog.file.entity.VirtualFile) File(java.io.File) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with FileUploader

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;
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException)

Example 5 with FileUploader

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());
    }
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Aggregations

FileUploader (com.zyd.blog.file.FileUploader)8 GlobalFileUploader (com.zyd.blog.plugin.file.GlobalFileUploader)8 VirtualFile (com.zyd.blog.file.entity.VirtualFile)6 GlobalFileException (com.zyd.blog.file.exception.GlobalFileException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 RedisCache (com.zyd.blog.business.annotation.RedisCache)1 File (com.zyd.blog.business.entity.File)1 ZhydArticleException (com.zyd.blog.framework.exception.ZhydArticleException)1 BizFile (com.zyd.blog.persistence.beans.BizFile)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1