com.ruoyi.common.exception.file.FileNameLengthLimitExceededException Java Examples

The following examples show how to use com.ruoyi.common.exception.file.FileNameLengthLimitExceededException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileUploadUtils.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 文件上传
 *
 * @param baseDir 相对应用的基目录
 * @param file 上传的文件
 * @param extension 上传文件类型
 * @return 返回上传成功的文件名
 * @throws FileSizeLimitExceededException 如果超出最大大小
 * @throws FileNameLengthLimitExceededException 文件名太长
 * @throws IOException 比如读写文件出错时
 * @throws InvalidExtensionException 文件校验异常
 */
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
        throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
        InvalidExtensionException
{
    int fileNamelength = file.getOriginalFilename().length();
    if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
    {
        throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
    }

    assertAllowed(file, allowedExtension);

    String fileName = extractFilename(file);

    File desc = getAbsoluteFile(baseDir, fileName);
    file.transferTo(desc);
    String pathFileName = getPathFileName(baseDir, fileName);
    return pathFileName;
}
 
Example #2
Source File: FileUploadUtils.java    From RuoYi-Vue with MIT License 6 votes vote down vote up
/**
 * 文件上传
 *
 * @param baseDir 相对应用的基目录
 * @param file 上传的文件
 * @param extension 上传文件类型
 * @return 返回上传成功的文件名
 * @throws FileSizeLimitExceededException 如果超出最大大小
 * @throws FileNameLengthLimitExceededException 文件名太长
 * @throws IOException 比如读写文件出错时
 * @throws InvalidExtensionException 文件校验异常
 */
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
        throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
        InvalidExtensionException
{
    int fileNamelength = file.getOriginalFilename().length();
    if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
    {
        throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
    }

    assertAllowed(file, allowedExtension);

    String fileName = extractFilename(file);

    File desc = getAbsoluteFile(baseDir, fileName);
    file.transferTo(desc);
    String pathFileName = getPathFileName(baseDir, fileName);
    return pathFileName;
}
 
Example #3
Source File: FileUploadUtils.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 文件上传
 *
 * @param baseDir   相对应用的基目录
 * @param file      上传的文件
 * @param extension 上传文件类型
 * @return 返回上传成功的文件名
 * @throws FileSizeLimitExceededException       如果超出最大大小
 * @throws FileNameLengthLimitExceededException 文件名太长
 * @throws IOException                          比如读写文件出错时
 */
public static final String upload(String baseDir, MultipartFile file, String extension)
        throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException {

    int fileNamelength = file.getOriginalFilename().length();
    if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
        throw new FileNameLengthLimitExceededException(
                file.getOriginalFilename(), fileNamelength, FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
    }

    assertAllowed(file);

    String fileName = encodingFilename(file.getOriginalFilename(), extension);

    File desc = getAbsoluteFile(baseDir, baseDir + fileName);
    file.transferTo(desc);
    return fileName;
}
 
Example #4
Source File: FileUploadUtils.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
/**
 * 文件上传
 *
 * @param baseDir 相对应用的基目录
 * @param file    上传的文件
 * @return 返回上传成功的文件名
 * @throws FileSizeLimitExceededException       如果超出最大大小
 * @throws FileNameLengthLimitExceededException 文件名太长
 * @throws IOException                          比如读写文件出错时
 */
public static String upload(String baseDir, MultipartFile file, String[] allowedExtension)
        throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, InvalidExtensionException {

    int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
    if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
        throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
    }

    assertAllowed(file, allowedExtension);

    String fileName = extractFilename(file);

    File desc = getAbsoluteFile(baseDir, fileName);
    file.transferTo(desc);
    return fileName;
}