Java Code Examples for com.ruoyi.common.exception.file.InvalidExtensionException#InvalidMediaExtensionException

The following examples show how to use com.ruoyi.common.exception.file.InvalidExtensionException#InvalidMediaExtensionException . 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 RuoYi with 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 2
Source File: FileUploadUtils.java    From supplierShop with 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 3
Source File: FileUploadUtils.java    From RuoYi-Vue with 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);
        }
    }

}