upload.check - Check That Uploaded Files are Valid
Check for basic file information and limits.
- upload.check.accept_file(filename: str, filesize: int, file: UploadedFile) dict
Determine if a new file should be accepted.
- Parameters:
filename – The name of the file to check
filesize – The size of the file in bytes
file – The object containing the file data
These checks are applied:
The file name is safe and not malicious
The file name is not empty
The file has an accepted extension
The file’s MIME type matches the expected MIME type for the extension
The file’s size is an integer greater than zero
The file’s size is less than or equal to the maximum allowed size for one file
- Returns:
A dictionary containing an ‘accepted’ key that contains True if the session is valid, or False if not. The dictionary also contains an ‘error’ and ‘verboseError’ key if ‘accepted’ is False.
- upload.check.accept_session(filename: str, filesize: str | int, session: UploadSession) dict
Determine if a new file should be accepted as part of the session.
These checks are applied:
The session has room for more files according to the MAX_TOTAL_UPLOAD_COUNT
The session has room for more files according to the MAX_TOTAL_UPLOAD_SIZE_MB
A file with the same name has not already been uploaded
- Parameters:
filename (str) – The name of the file
filesize (Union[str, int]) – A string or integer representing the size of the file (in bytes)
session (UploadSession) – The session files are being uploaded to
- Returns:
A dictionary containing an ‘accepted’ key that contains True if the session is valid, or False if not. The dictionary also contains an ‘error’ and ‘verboseError’ key if ‘accepted’ is False.