Search in sources :

Example 6 with OSSFile

use of org.jeecg.modules.oss.entity.OSSFile in project kms by mahonelau.

the class SysUploadController method uploadMinio.

/**
 * 上传
 * @param request
 */
@PostMapping(value = "/uploadMinio")
public Result<?> uploadMinio(HttpServletRequest request) {
    Result<?> result = new Result<>();
    String bizPath = request.getParameter("biz");
    if (oConvertUtils.isEmpty(bizPath)) {
        bizPath = "";
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    // 获取上传文件对象
    MultipartFile file = multipartRequest.getFile("file");
    // 获取文件名
    String orgName = file.getOriginalFilename();
    orgName = CommonUtils.getFileName(orgName);
    String file_url = MinioUtil.upload(file, bizPath);
    if (oConvertUtils.isEmpty(file_url)) {
        return Result.error("上传失败,请检查配置信息是否正确!");
    }
    // 保存文件信息
    OSSFile minioFile = new OSSFile();
    minioFile.setFileName(orgName);
    minioFile.setUrl(file_url);
    ossFileService.save(minioFile);
    result.setMessage(file_url);
    result.setSuccess(true);
    return result;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) OSSFile(org.jeecg.modules.oss.entity.OSSFile) Result(org.jeecg.common.api.vo.Result) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 7 with OSSFile

use of org.jeecg.modules.oss.entity.OSSFile in project kms by mahonelau.

the class OSSFileServiceImpl method upload.

@Override
public void upload(MultipartFile multipartFile) throws IOException {
    String fileName = multipartFile.getOriginalFilename();
    fileName = CommonUtils.getFileName(fileName);
    OSSFile ossFile = new OSSFile();
    ossFile.setFileName(fileName);
    String url = OssBootUtil.upload(multipartFile, "upload/test");
    // update-begin--Author:scott  Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
    // 返回阿里云原生域名前缀URL
    ossFile.setUrl(OssBootUtil.getOriginalUrl(url));
    // update-end--Author:scott  Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
    this.save(ossFile);
}
Also used : OSSFile(org.jeecg.modules.oss.entity.OSSFile)

Example 8 with OSSFile

use of org.jeecg.modules.oss.entity.OSSFile in project kms by mahonelau.

the class OSSFileController method queryById.

/**
 * 通过id查询.
 */
@ResponseBody
@GetMapping("/queryById")
public Result<OSSFile> queryById(@RequestParam(name = "id") String id) {
    Result<OSSFile> result = new Result<>();
    OSSFile file = ossFileService.getById(id);
    if (file == null) {
        result.error500("未找到对应实体");
    } else {
        result.setResult(file);
        result.setSuccess(true);
    }
    return result;
}
Also used : OSSFile(org.jeecg.modules.oss.entity.OSSFile) Result(org.jeecg.common.api.vo.Result) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with OSSFile

use of org.jeecg.modules.oss.entity.OSSFile in project kms by mahonelau.

the class OSSFileController method delete.

@ResponseBody
@DeleteMapping("/delete")
public Result delete(@RequestParam(name = "id") String id) {
    Result result = new Result();
    OSSFile file = ossFileService.getById(id);
    if (file == null) {
        result.error500("未找到对应实体");
    } else {
        boolean ok = ossFileService.delete(file);
        if (ok) {
            result.success("删除成功!");
        }
    }
    return result;
}
Also used : OSSFile(org.jeecg.modules.oss.entity.OSSFile) Result(org.jeecg.common.api.vo.Result) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with OSSFile

use of org.jeecg.modules.oss.entity.OSSFile in project jeecg-boot by jeecgboot.

the class OSSFileServiceImpl method upload.

@Override
public void upload(MultipartFile multipartFile) throws IOException {
    String fileName = multipartFile.getOriginalFilename();
    fileName = CommonUtils.getFileName(fileName);
    OSSFile ossFile = new OSSFile();
    ossFile.setFileName(fileName);
    String url = OssBootUtil.upload(multipartFile, "upload/test");
    // update-begin--Author:scott  Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
    // 返回阿里云原生域名前缀URL
    ossFile.setUrl(OssBootUtil.getOriginalUrl(url));
    // update-end--Author:scott  Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
    this.save(ossFile);
}
Also used : OSSFile(org.jeecg.modules.oss.entity.OSSFile)

Aggregations

OSSFile (org.jeecg.modules.oss.entity.OSSFile)12 Result (org.jeecg.common.api.vo.Result)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)3 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 JeecgBootException (org.jeecg.common.exception.JeecgBootException)1