Java Code Examples for com.ruoyi.common.exception.file.FileSizeLimitExceededException

The following examples show how to use com.ruoyi.common.exception.file.FileSizeLimitExceededException. These examples are extracted from open source projects. 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 Project: supplierShop   Source File: FileUploadUtils.java    License: 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 Project: RuoYi-Vue   Source File: FileUploadUtils.java    License: 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 Project: RuoYi   Source File: FileUploadUtils.java    License: 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;
}
 
Example 4
Source Project: RuoYi   Source File: FileUploadUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 文件大小校验
 *
 * @param file 上传的文件
 * @return
 * @throws FileSizeLimitExceededException 如果超出最大大小
 */
private static void assertAllowed(MultipartFile file, String[] allowedExtension) throws FileSizeLimitExceededException, InvalidExtensionException {
    long size = file.getSize();
    if (size > DEFAULT_MAX_SIZE) {
        throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
    }
    String filename = file.getOriginalFilename();
    String extension = getExtension(file);
    if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) {
        if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) {
            throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension, filename);
        } else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) {
            throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension, filename);
        } else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) {
            throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension, filename);
        } else {
            throw new InvalidExtensionException(allowedExtension, extension, filename);
        }
    }
}
 
Example 5
Source Project: supplierShop   Source File: FileUploadUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 文件大小校验
 *
 * @param file 上传的文件
 * @return
 * @throws FileSizeLimitExceededException 如果超出最大大小
 * @throws InvalidExtensionException
 */
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
        throws FileSizeLimitExceededException, InvalidExtensionException
{
    long size = file.getSize();
    if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE)
    {
        throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
    }

    String fileName = file.getOriginalFilename();
    String extension = getExtension(file);
    if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
    {
        if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
        {
            throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
                    fileName);
        }
        else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
        {
            throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
                    fileName);
        }
        else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
        {
            throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
                    fileName);
        }
        else
        {
            throw new InvalidExtensionException(allowedExtension, extension, fileName);
        }
    }

}
 
Example 6
Source Project: RuoYi-Vue   Source File: FileUploadUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 文件大小校验
 *
 * @param file 上传的文件
 * @return
 * @throws FileSizeLimitExceededException 如果超出最大大小
 * @throws InvalidExtensionException
 */
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
        throws FileSizeLimitExceededException, InvalidExtensionException
{
    long size = file.getSize();
    if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE)
    {
        throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
    }

    String fileName = file.getOriginalFilename();
    String extension = getExtension(file);
    if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
    {
        if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
        {
            throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
                    fileName);
        }
        else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
        {
            throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
                    fileName);
        }
        else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
        {
            throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
                    fileName);
        }
        else
        {
            throw new InvalidExtensionException(allowedExtension, extension, fileName);
        }
    }

}