Search in sources :

Example 1 with UploadFileResult

use of com.diboot.file.dto.UploadFileResult in project diboot by dibo-software.

the class BaseFileController method saveFile.

/**
 * 保存文件
 *
 * @param inputStream
 * @param fileName
 * @return
 * @throws Exception
 */
protected UploadFile saveFile(InputStream inputStream, String fileName) throws Exception {
    UploadFileResult uploadFileResult = fileStorageService.upload(inputStream, fileName);
    String accessUrl = buildAccessUrl(uploadFileResult.getFilename());
    UploadFile uploadFile = new UploadFile();
    uploadFile.setUuid(uploadFileResult.getUuid()).setFileName(uploadFileResult.getOriginalFilename()).setFileType(uploadFileResult.getExt()).setStoragePath(uploadFileResult.getStorageFullPath()).setAccessUrl(accessUrl);
    // 返回uploadFile对象
    return uploadFile;
}
Also used : UploadFile(com.diboot.file.entity.UploadFile) UploadFileResult(com.diboot.file.dto.UploadFileResult)

Example 2 with UploadFileResult

use of com.diboot.file.dto.UploadFileResult in project diboot by dibo-software.

the class LocalFileStorageServiceImpl method upload.

@Override
public UploadFileResult upload(InputStream inputStream, String fileName) throws Exception {
    UploadFileResult uploadFileResult = new UploadFileResult();
    // 文件后缀
    String fileUid = S.newUuid();
    String ext = FileHelper.getFileExtByName(fileName);
    String newFileName = fileUid + "." + ext;
    String fileFullPath = FileHelper.saveFile(inputStream, newFileName);
    uploadFileResult.setOriginalFilename(fileName).setExt(ext).setUuid(fileUid).setFilename(newFileName).setStorageFullPath(fileFullPath);
    return uploadFileResult;
}
Also used : UploadFileResult(com.diboot.file.dto.UploadFileResult)

Example 3 with UploadFileResult

use of com.diboot.file.dto.UploadFileResult in project diboot by dibo-software.

the class LocalFileStorageServiceImpl method upload.

@Override
public UploadFileResult upload(MultipartFile file) throws Exception {
    UploadFileResult uploadFileResult = new UploadFileResult();
    // 文件后缀
    String fileUid = S.newUuid();
    String ext = FileHelper.getFileExtByName(file.getOriginalFilename());
    String newFileName = fileUid + "." + ext;
    String fileFullPath = FileHelper.saveFile(file, newFileName);
    uploadFileResult.setOriginalFilename(file.getOriginalFilename()).setExt(ext).setUuid(fileUid).setFilename(newFileName).setStorageFullPath(fileFullPath);
    return uploadFileResult;
}
Also used : UploadFileResult(com.diboot.file.dto.UploadFileResult)

Example 4 with UploadFileResult

use of com.diboot.file.dto.UploadFileResult in project diboot by dibo-software.

the class BaseFileController method saveFile.

/**
 * 保存文件
 * @param file
 * @param entityClass
 * @param <T>
 * @return
 * @throws Exception
 */
protected <T> UploadFile saveFile(MultipartFile file, Class<T> entityClass) throws Exception {
    UploadFileResult uploadFileResult = fileStorageService.upload(file);
    UploadFile uploadFile = new UploadFile();
    uploadFile.setUuid(uploadFileResult.getUuid()).setFileName(uploadFileResult.getOriginalFilename()).setFileType(uploadFileResult.getExt()).setRelObjType(entityClass.getSimpleName()).setStoragePath(uploadFileResult.getStorageFullPath());
    String accessUrl = buildAccessUrl(uploadFileResult.getFilename());
    uploadFile.setAccessUrl(accessUrl);
    String description = getString("description");
    uploadFile.setDescription(description);
    // 返回uploadFile对象
    return uploadFile;
}
Also used : UploadFile(com.diboot.file.entity.UploadFile) UploadFileResult(com.diboot.file.dto.UploadFileResult)

Example 5 with UploadFileResult

use of com.diboot.file.dto.UploadFileResult in project diboot by dibo-software.

the class BaseFileController method saveFile.

/**
 * 保存文件
 * @param uploadFileFormDTO
 * @return
 * @throws Exception
 */
protected UploadFile saveFile(UploadFileFormDTO uploadFileFormDTO) throws Exception {
    UploadFileResult uploadFileResult = fileStorageService.upload(uploadFileFormDTO.getFile());
    String accessUrl = buildAccessUrl(uploadFileResult.getFilename());
    UploadFile uploadFile = new UploadFile();
    uploadFile.setUuid(uploadFileResult.getUuid()).setFileName(uploadFileResult.getOriginalFilename()).setFileType(uploadFileResult.getExt()).setRelObjType(uploadFileFormDTO.getRelObjType()).setRelObjField(uploadFileFormDTO.getRelObjField()).setStoragePath(uploadFileResult.getStorageFullPath()).setAccessUrl(accessUrl).setDescription(uploadFileFormDTO.getDescription());
    // 返回uploadFile对象
    return uploadFile;
}
Also used : UploadFile(com.diboot.file.entity.UploadFile) UploadFileResult(com.diboot.file.dto.UploadFileResult)

Aggregations

UploadFileResult (com.diboot.file.dto.UploadFileResult)5 UploadFile (com.diboot.file.entity.UploadFile)3