Search in sources :

Example 1 with UploadResult

use of com.ruoyi.oss.entity.UploadResult in project RuoYi-Vue-Plus by JavaLionLi.

the class SysOssServiceImpl method upload.

@Override
public SysOss upload(MultipartFile file) {
    String originalfileName = file.getOriginalFilename();
    String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
    IOssStrategy storage = OssFactory.instance();
    UploadResult uploadResult;
    try {
        uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
    } catch (IOException e) {
        throw new ServiceException(e.getMessage());
    }
    // 保存文件信息
    SysOss oss = new SysOss();
    oss.setUrl(uploadResult.getUrl());
    oss.setFileSuffix(suffix);
    oss.setFileName(uploadResult.getFilename());
    oss.setOriginalName(originalfileName);
    oss.setService(storage.getServiceType().getValue());
    baseMapper.insert(oss);
    return oss;
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) IOssStrategy(com.ruoyi.oss.service.IOssStrategy) UploadResult(com.ruoyi.oss.entity.UploadResult) IOException(java.io.IOException)

Example 2 with UploadResult

use of com.ruoyi.oss.entity.UploadResult in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysOssServiceImpl method upload.

@Override
public SysOss upload(MultipartFile file) {
    String originalfileName = file.getOriginalFilename();
    String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
    IOssStrategy storage = OssFactory.instance();
    UploadResult uploadResult;
    try {
        uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
    } catch (IOException e) {
        throw new ServiceException(e.getMessage());
    }
    // 保存文件信息
    SysOss oss = new SysOss();
    oss.setUrl(uploadResult.getUrl());
    oss.setFileSuffix(suffix);
    oss.setFileName(uploadResult.getFilename());
    oss.setOriginalName(originalfileName);
    oss.setService(storage.getServiceType().getValue());
    baseMapper.insert(oss);
    return oss;
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) IOssStrategy(com.ruoyi.oss.service.IOssStrategy) UploadResult(com.ruoyi.oss.entity.UploadResult) IOException(java.io.IOException)

Aggregations

ServiceException (com.ruoyi.common.exception.ServiceException)2 UploadResult (com.ruoyi.oss.entity.UploadResult)2 IOssStrategy (com.ruoyi.oss.service.IOssStrategy)2 SysOss (com.ruoyi.system.domain.SysOss)2 IOException (java.io.IOException)2