Search in sources :

Example 11 with VirtualFile

use of com.zyd.blog.file.entity.VirtualFile 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)

Example 12 with VirtualFile

use of com.zyd.blog.file.entity.VirtualFile 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)

Example 13 with VirtualFile

use of com.zyd.blog.file.entity.VirtualFile in project OneBlog by zhangyd-c.

the class BaseFileUploader method saveFile.

VirtualFile saveFile(VirtualFile virtualFile, boolean save, String uploadType) {
    if (save) {
        BizFileService fileService = SpringContextHolder.getBean(BizFileService.class);
        try {
            SysConfigService configService = SpringContextHolder.getBean(SysConfigService.class);
            Map<String, Object> config = configService.getConfigs();
            String storageType = (String) config.get(ConfigKeyEnum.STORAGE_TYPE.getKey());
            BizFile fileInfo = BeanConvertUtil.doConvert(virtualFile, BizFile.class);
            User sessionUser = SessionUtil.getUser();
            fileInfo.setUserId(null == sessionUser ? null : sessionUser.getId());
            fileInfo.setUploadType(uploadType);
            fileInfo.setStorageType(storageType);
            fileService.insert(new File(fileInfo));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return virtualFile;
}
Also used : User(com.zyd.blog.business.entity.User) SysConfigService(com.zyd.blog.business.service.SysConfigService) BizFileService(com.zyd.blog.business.service.BizFileService) VirtualFile(com.zyd.blog.file.entity.VirtualFile) BizFile(com.zyd.blog.persistence.beans.BizFile) File(com.zyd.blog.business.entity.File) ZhydException(com.zyd.blog.framework.exception.ZhydException) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException) BizFile(com.zyd.blog.persistence.beans.BizFile)

Example 14 with VirtualFile

use of com.zyd.blog.file.entity.VirtualFile in project OneBlog by zhangyd-c.

the class GlobalFileUploader method upload.

@Override
public VirtualFile upload(MultipartFile file, String uploadType, boolean save) {
    ApiClient apiClient = this.getApiClient(uploadType);
    VirtualFile virtualFile = apiClient.uploadImg(file);
    return this.saveFile(virtualFile, save, uploadType);
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) ApiClient(com.zyd.blog.file.ApiClient)

Example 15 with VirtualFile

use of com.zyd.blog.file.entity.VirtualFile in project OneBlog by zhangyd-c.

the class GlobalFileUploader method upload.

@Override
public VirtualFile upload(File file, String uploadType, boolean save) {
    ApiClient apiClient = this.getApiClient(uploadType);
    VirtualFile virtualFile = apiClient.uploadImg(file);
    return this.saveFile(virtualFile, save, uploadType);
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) ApiClient(com.zyd.blog.file.ApiClient)

Aggregations

VirtualFile (com.zyd.blog.file.entity.VirtualFile)15 FileUploader (com.zyd.blog.file.FileUploader)6 GlobalFileUploader (com.zyd.blog.plugin.file.GlobalFileUploader)6 GlobalFileException (com.zyd.blog.file.exception.GlobalFileException)4 ApiClient (com.zyd.blog.file.ApiClient)3 Date (java.util.Date)3 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)2 OssApiException (com.zyd.blog.file.exception.OssApiException)2 QiniuApiException (com.zyd.blog.file.exception.QiniuApiException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 QiniuException (com.qiniu.common.QiniuException)1 Response (com.qiniu.http.Response)1 Configuration (com.qiniu.storage.Configuration)1 UploadManager (com.qiniu.storage.UploadManager)1 DefaultPutRet (com.qiniu.storage.model.DefaultPutRet)1 Auth (com.qiniu.util.Auth)1 RedisCache (com.zyd.blog.business.annotation.RedisCache)1