Search in sources :

Example 6 with GlobalFileUploader

use of com.zyd.blog.plugin.file.GlobalFileUploader in project OneBlog by zhangyd-c.

the class BizFileServiceImpl method upload.

@Override
@Transactional(rollbackFor = Exception.class)
public int upload(MultipartFile[] file) {
    if (null == file || file.length == 0) {
        throw new GlobalFileException("请至少选择一张图片!");
    }
    for (MultipartFile multipartFile : file) {
        FileUploader uploader = new GlobalFileUploader();
        uploader.upload(multipartFile, FileUploadType.COMMON.getPath(), true);
    }
    return file.length;
}
Also used : GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) MultipartFile(org.springframework.web.multipart.MultipartFile) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with GlobalFileUploader

use of com.zyd.blog.plugin.file.GlobalFileUploader in project OneBlog by zhangyd-c.

the class BizFileServiceImpl method remove.

@Override
@Transactional(rollbackFor = Exception.class)
public void remove(Long[] ids) {
    for (Long id : ids) {
        File oldFile = this.getByPrimaryKey(id);
        this.removeByPrimaryKey(id);
        try {
            FileUploader uploader = new GlobalFileUploader();
            uploader.delete(oldFile.getFilePath(), oldFile.getUploadType());
        } catch (Exception ignored) {
        }
    }
}
Also used : GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) BizFile(com.zyd.blog.persistence.beans.BizFile) MultipartFile(org.springframework.web.multipart.MultipartFile) File(com.zyd.blog.business.entity.File) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with GlobalFileUploader

use of com.zyd.blog.plugin.file.GlobalFileUploader in project OneBlog by zhangyd-c.

the class RestApiController method uploadFileForMd.

@BussinessLog("simpleMD编辑器中上传文件")
@RequiresPermissions("article:publish")
@PostMapping("/uploadFileForMd")
public Object uploadFileForMd(@RequestParam("file") MultipartFile file) {
    FileUploader uploader = new GlobalFileUploader();
    VirtualFile virtualFile = uploader.upload(file, FileUploadType.SIMPLE.getPath(), true);
    Map<String, Object> resultMap = new HashMap<>(3);
    resultMap.put("success", 1);
    resultMap.put("message", "上传成功");
    resultMap.put("filename", virtualFile.getFullFilePath());
    return resultMap;
}
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) HashMap(java.util.HashMap) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

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